Ruifeng Zheng created SPARK-62406:
-------------------------------------

             Summary: Defer Arrow input cleanup during active writes
                 Key: SPARK-62406
                 URL: https://issues.apache.org/jira/browse/SPARK-62406
             Project: Spark
          Issue Type: Bug
          Components: SQL
    Affects Versions: 5.0.0
            Reporter: Ruifeng Zheng


PythonArrowInput can release its Arrow input buffers while a write is still 
active on a helper thread.

SPARK-60737 added task-completion cleanup for input that is not exhausted. Its 
listener assumes input writing has stopped. That holds for execution on the 
task thread and for the dedicated pipelined Python writer, whose pre-completion 
listener waits for it to stop. However, callers such as PipedRDD can consume 
the upstream iterator on their own helper threads, which can outlive the task 
body. The completion listener can then close the Arrow root and allocator while 
that input write still uses them.

The fix tracks active input writing under a shared lock, defers cleanup to the 
active write's finally block, and rejects writes after task completion. 
Upstream iteration and Arrow serialization stay outside the lock so completion 
does not wait for upstream I/O. Cleanup remains idempotent, preserves normal 
EOF handling, and does not write an Arrow footer during task completion. 
Stateful Python runners inherit the protection through PythonArrowInput.

Validation: 12 deterministic lifecycle cases cover ordinary and stateful 
writers, including completion before the first write, successful and failing 
concurrent writes, EOF, and idle completion. All four active-write cases fail 
against the original implementation because the allocator has already been 
released. With the fix, 16 targeted tests and production/test Scala style 
checks pass.

PR: https://github.com/apache/spark/pull/60843
Related original change: https://issues.apache.org/jira/browse/SPARK-60737




--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

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

Reply via email to