HyukjinKwon commented on code in PR #60423:
URL: https://github.com/apache/spark/pull/60423#discussion_r4562133953
##########
python/pyspark/sql/connect/streaming/query.py:
##########
@@ -287,7 +287,10 @@ def __init__(self, sqm: "StreamingQueryManager") -> None:
self._bus_lock = Lock()
def close(self) -> None:
- for listener in self._listener_bus:
+ # remove() deletes from _listener_bus, so iterate over a snapshot
taken under the lock.
+ with self._bus_lock:
+ listeners = list(self._listener_bus)
+ for listener in listeners:
self.remove(listener)
Review Comment:
Thanks, @dongjoon-hyun. Good catch, and I agree. Fixed in 406ed4b: when
`self._sqm._session.client.is_closed`, `close()` now only clears the local
listeners and the handler thread reference, and sends no server-side removal.
Releasing the session has already removed the server-side listener, and the
handler thread ends with the event stream, so `close()` does not join it
either. That matters because it runs from `__del__`.
The new test,
`test_close_with_a_closed_client_clears_the_listeners_without_a_removal`,
closes a bus of two listeners on a closed client. It checks that no removal is
sent, no warning is raised, and the bus is empty. Without the change, it fails
with exactly the warning you described: "Failed to remove the listener because
of exception: ... please remove it again.". The existing test now sets
`is_closed = False` on its mocked client.
--
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]