Skip to content

Potential race condition in BaseOperationImpl.java #43

Open
@MusaTalluzi

Description

@MusaTalluzi

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 on i.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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions