Github user JoshRosen commented on a diff in the pull request:

    https://github.com/apache/spark/pull/4135#discussion_r26236576
  
    --- Diff: core/src/main/scala/org/apache/spark/TaskContextImpl.scala ---
    @@ -66,8 +66,21 @@ private[spark] class TaskContextImpl(
       /** Marks the task as completed and triggers the listeners. */
       private[spark] def markTaskCompleted(): Unit = {
         completed = true
    +    processCallBacks()
    +  }
    +
    +  /** Marks the task for interruption, i.e. cancellation. */
    +  private[spark] def markInterrupted(): Unit = {
    +    interrupted = true
    +    processCallBacks()
    --- End diff --
    
    Actually, tale a look at the definition of `Task.run`:
    
    ```scala
      final def run(attemptId: Long): T = {
        context = new TaskContextImpl(stageId, partitionId, attemptId, false)
        TaskContextHelper.setTaskContext(context)
        context.taskMetrics.hostname = Utils.localHostName()
        taskThread = Thread.currentThread()
        if (_killed) {
          kill(interruptThread = false)
        }
        try {
          runTask(context)
        } finally {
          context.markTaskCompleted()
          TaskContextHelper.unset()
        }
      }
    ```
    
    If `_killed` is true, then we'll call `kill()` which marks the task context 
as interrupted, and then still call `runTask`, so the `finally` block will mark 
the task as completed after it's already been interrupted.  Therefore, I don't 
think that triggering call backprocessing inside of `markInterrupted` is the 
right approach, especially since `Task.kill()` is asynchronous, so the task 
could still be running at this point.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to