viirya commented on code in PR #59565:
URL: https://github.com/apache/spark/pull/59565#discussion_r4301623294


##########
core/src/main/scala/org/apache/spark/api/python/PythonRunner.scala:
##########
@@ -1059,6 +1059,11 @@ private[spark] abstract class BasePythonRunner[IN, OUT](
     private[this] var writerIfbhThreadLocalValue: Object = null
     private[this] val temp = new Array[Byte](1)
     private[this] val bufferStream = new DirectByteBufferOutputStream()
+    // The writer gets `bufferStream` only through this stream. Arrow writers 
write through an
+    // interruptible channel, so a task kill that interrupts this thread 
closes the stream they
+    // write to on the killing thread; that must not free `bufferStream` under 
the writer. It is
+    // freed only by `bufferStream.close()` below. See 
`CloseShieldOutputStream`.

Review Comment:
   Good catch. `writeAdditionalInputToPythonWorker()` now wraps the original 
body, renamed to `writeBufferedInputToPythonWorker()`. When an exception 
escapes it, it frees `bufferStream` on the thread that writes into it and sets 
`hasInput = false` and an empty `buffer`, so a later call does not touch the 
freed buffer. That covers a kill during a write as well as writer and socket 
write failures. The interrupting thread only reaches the no-op `flush()` calls, 
so freeing here does not race with it. I updated this comment and the 
description, and the `ReaderInputStream` test now also checks that the buffer 
is freed after the interrupted write.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to