Open
Description
Our profiler shows BaseOperationImpl.isCancelled
spends 90% of the time in blocked state and we suspect it's causing deadlocks since it shares the same lock with other operations in the Operation class:
public final synchronized boolean isCancelled() {
return cancelled;
}
public final synchronized void cancel() {
cancelled = true;
synchronized (clones) {
Iterator<Operation> i = clones.iterator();
while(i.hasNext()) {
i.next().cancel();
}
}
wasCancelled();
callback.receivedStatus(CANCELLED);
callback.complete();
}
If the operation is cloned (original X, clone Y) and two threads call cancel()
:
- Thread A calls
X.cancel()
, aquires X's lock and yields - Thread B calls
Y.cancel()
, aquires Y's lock, enters synchronized block,i.next()
returns X, thread blocks oni.next().cancel()
since thread A is already executing that function - Thread A resumes execution, its
i.next()
returns A and it blocks similar to B
Is this a valid situation that could happen?
Metadata
Metadata
Assignees
Labels
No labels