You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "anishshri-db (via GitHub)" <gi...@apache.org> on 2023/08/15 18:57:26 UTC

[GitHub] [spark] anishshri-db opened a new pull request, #42504: [SPARK-44818] Fix race for pending interrupt issued before taskThread is initialized

anishshri-db opened a new pull request, #42504:
URL: https://github.com/apache/spark/pull/42504

   ### What changes were proposed in this pull request?
   Fix race for pending interrupt issued before taskThread is initialized
   
   ### Why are the changes needed?
   We see that there is a race for tasks that are interrupted through stage cancellation and that may be added to the TaskSet, but don't yet have taskThread initialized.
   
   Basically, we try to kill ongoing task attempts to handle stage cancellation
   
   ```
       logInfo("Cancelling stage " + stageId)
       // Kill all running tasks for the stage.
       killAllTaskAttempts(stageId, interruptThread, reason = "Stage cancelled: " + reason)
       // Cancel all attempts for the stage.
   ```
   
   However, there is a chance that taskThread is not initialized yet and we only set the reasonIfKilled.
   
   ```
     def kill(interruptThread: Boolean, reason: String): Unit = {
       require(reason != null)
       _reasonIfKilled = reason
       if (context != null) {
         context.markInterrupted(reason)
       }
       if (interruptThread && taskThread != null) {
         taskThread.interrupt().  <--- never hit
       }
   ```
   
   Then within the task execution thread itself, we try to call kill again since the reasonIfKilled is set. However, this time we pass interruptThread as false explicitly since we don't know the status of the previous call.
   
   ```
       taskThread = Thread.currentThread()
   
       if (_reasonIfKilled != null) {
         kill(interruptThread = false, _reasonIfKilled) <-- only context will be set, 
       }
   ```
   
   The TaskReaper has also finished its previous and only attempt at task interruption since we don't try for multiple times in this case. Eventually, the task is not interrupted even once and it gets blocked on some I/O or wait calls which might not finish within the reaper timeout, leading to the JVM being killed.
   
   ```
           taskRunner.kill(interruptThread = interruptThread, reason = reason)
   ```
   
   The change tries to fix this issue by trying to explicitly interrupt the thread in case a previous requested interrupt was not serviced.
   
   ### Does this PR introduce _any_ user-facing change?
   No
   
   
   ### How was this patch tested?
   Existing unit tests
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] anishshri-db commented on pull request #42504: [SPARK-44818] Fix race for pending interrupt issued before taskThread is initialized

Posted by "anishshri-db (via GitHub)" <gi...@apache.org>.
anishshri-db commented on PR #42504:
URL: https://github.com/apache/spark/pull/42504#issuecomment-1679377999

   @jiangxb1987 @HeartSaVioR - PTAL, thx !


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] anishshri-db commented on pull request #42504: [SPARK-44818] Fix race for pending task kill issued before taskThread is initialized

Posted by "anishshri-db (via GitHub)" <gi...@apache.org>.
anishshri-db commented on PR #42504:
URL: https://github.com/apache/spark/pull/42504#issuecomment-1684573981

   > I'm fine with leaving the plugin code as-is until we have evidence that problems are occurring there in practice. I'd bet that the combination of "stage cancellation + task reaper + executor plugin + slow IO in executor plugin" is sufficiently rare that there's not a strong motivation to guard against edge cases there, so I'm fine erring on the side of caution by not making changes there (thereby avoiding risks of unanticipated side effects, etc).
   Yup agreed.
   
   > Do you mind updating the PR description to reflect the final changes?
   Done


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] anishshri-db commented on pull request #42504: [SPARK-44818] Fix race for pending task kill issued before taskThread is initialized

Posted by "anishshri-db (via GitHub)" <gi...@apache.org>.
anishshri-db commented on PR #42504:
URL: https://github.com/apache/spark/pull/42504#issuecomment-1685115681

   @JoshRosen @HeartSaVioR - could one of you pls merge when you get a chance ? Thx


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] mridulm commented on pull request #42504: [SPARK-44818] Fix race for pending interrupt issued before taskThread is initialized

Posted by "mridulm (via GitHub)" <gi...@apache.org>.
mridulm commented on PR #42504:
URL: https://github.com/apache/spark/pull/42504#issuecomment-1679917506

   +CC @JoshRosen 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] JoshRosen commented on pull request #42504: [SPARK-44818] Fix race for pending task kill issued before taskThread is initialized

Posted by "JoshRosen (via GitHub)" <gi...@apache.org>.
JoshRosen commented on PR #42504:
URL: https://github.com/apache/spark/pull/42504#issuecomment-1686995314

   Merged to master. Thanks @anishshri-db!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] JoshRosen closed pull request #42504: [SPARK-44818] Fix race for pending task kill issued before taskThread is initialized

Posted by "JoshRosen (via GitHub)" <gi...@apache.org>.
JoshRosen closed pull request #42504: [SPARK-44818] Fix race for pending task kill issued before taskThread is initialized
URL: https://github.com/apache/spark/pull/42504


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] anishshri-db commented on pull request #42504: [SPARK-44818] Fix race for pending interrupt issued before taskThread is initialized

Posted by "anishshri-db (via GitHub)" <gi...@apache.org>.
anishshri-db commented on PR #42504:
URL: https://github.com/apache/spark/pull/42504#issuecomment-1684519240

   @JoshRosen - I addressed your comments. I think your proposal seems fine too. At the time that we throw this TaskKilled exception, the context should be non-null and should have the reason set even though interruptThread is passed as false. The issue of whether the plugins will block on I/O remains. We should possibly move that within this `try` after the check for killIfInterrupted maybe ? But in any case, the issues we have seen have been with threads that actually run the task execution and get blocked on some network I/O (remote RPC or otherwise) and whose timeouts are effectively larger than the reaper timeout causing us to block task slots and force a executor JVM kill eventually. Those majority of cases should be handled by your proposed fix, I believe. Let me know what you think. Thx


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] anishshri-db commented on pull request #42504: [SPARK-44818] Fix race for pending interrupt issued before taskThread is initialized

Posted by "anishshri-db (via GitHub)" <gi...@apache.org>.
anishshri-db commented on PR #42504:
URL: https://github.com/apache/spark/pull/42504#issuecomment-1681367472

   @jiangxb1987 @JoshRosen - could you folks please take a look ? Thx


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org