public WmTezSession cancelAndExtractSessionIfDone(String cancelReason, List<Path> toDelete) {
      lock.lock();
      try {
        SessionInitState state = this.state;
        this.state = SessionInitState.CANCELED;
        this.cancelReason = cancelReason;
        if (state == SessionInitState.DONE) {
          WmTezSession result = this.session;
          this.session = null;
          if (pathToDelete != null) {
            toDelete.add(pathToDelete);
          }
          return result;
        } else {
          // In the states where a background operation is in progress, wait for the callback.
          // Also, ignore any duplicate calls; also don't kill failed ones - handled elsewhere.
          if (state == SessionInitState.CANCELED) {
            LOG.warn("Duplicate call to extract " + session);
          }
          return null;
        }
      } finally {
        lock.unlock();
      }
    }
Cancel the async operation (even if it's done), and return the session if done.
ql/src/java/org/apache/hadoop/hive/ql/exec/tez/WorkloadManager.java