HyukjinKwon opened a new pull request, #60423:
URL: https://github.com/apache/spark/pull/60423

   ### What changes were proposed in this pull request?
   
   `StreamingQueryListenerBus.close()` in PySpark's Spark Connect client 
iterates over `_listener_bus` while `remove()` deletes from that same list, so 
the loop skips every other listener. This PR makes `close()` iterate over a 
snapshot of the list, taken under `_bus_lock`.
   
   ### Why are the changes needed?
   
   `close()` should remove every listener, and once the last one is removed, 
ask the server to remove its listener and stop the handler thread. With three 
listeners registered, it removes the first and the third and leaves the second, 
so the server-side listener and the handler thread stay alive after `close()`.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, for Spark Connect users with more than one streaming query listener: 
`close()` now removes all of them and releases the server-side listener.
   
   ### How was this patch tested?
   
   Added `StreamingQueryListenerBusCloseTests` in 
`python/pyspark/sql/tests/connect/streaming/test_listener.py`. It uses a mocked 
session client, so it needs no server. It registers three listeners, calls 
`close()`, and checks that the bus is empty, the handler thread is gone, and 
the server removal is sent once. It fails without this change, because the 
second listener remains.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Opus 5.5
   
   This pull request and its description were written by Isaac.
   


-- 
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