Fix: Reset _closing flag on WebSocket reconnection to ensure on_client_disconnected fires
The on_client_disconnected event handler was not firing after the first disconnection in long-running containers. The _closing flag was set to True on first disconnect and never reset, preventing subsequent disconnect events from being triggered. This fix resets the _closing flag to False in the setup() method, ensuring each new connection starts with a clean state.
This commit is contained in:
@@ -105,6 +105,8 @@ class FastAPIWebsocketClient:
|
|||||||
_: The start frame (unused).
|
_: The start frame (unused).
|
||||||
"""
|
"""
|
||||||
self._leave_counter += 1
|
self._leave_counter += 1
|
||||||
|
# Reset closing flag when setting up a new connection
|
||||||
|
self._closing = False
|
||||||
|
|
||||||
def receive(self) -> typing.AsyncIterator[bytes | str]:
|
def receive(self) -> typing.AsyncIterator[bytes | str]:
|
||||||
"""Get an async iterator for receiving WebSocket messages.
|
"""Get an async iterator for receiving WebSocket messages.
|
||||||
|
|||||||
Reference in New Issue
Block a user