From 671fb0a7e19a4a56a89f0769982304ac048939f1 Mon Sep 17 00:00:00 2001 From: rohith10e Date: Tue, 16 Dec 2025 22:16:51 +0530 Subject: [PATCH] fix(realtime): prevent channel from closing during auto-reconnect --- src/realtime/src/realtime/_async/channel.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/realtime/src/realtime/_async/channel.py b/src/realtime/src/realtime/_async/channel.py index b6171098..7ae04583 100644 --- a/src/realtime/src/realtime/_async/channel.py +++ b/src/realtime/src/realtime/_async/channel.py @@ -501,14 +501,21 @@ async def _resubscribe(self) -> None: def _broadcast_endpoint_url(self): return f"{http_endpoint_url(self.socket.http_endpoint)}/api/broadcast" - + async def _rejoin(self) -> None: if self.is_leaving: return - await self.socket._leave_open_topic(self.topic) + + # On reconnect, the server already considers the channel closed. + # Sending phx_leave causes the channel to close again during rejoin. self.state = ChannelStates.JOINING + + # Reset join push refs to avoid stale replies + self.join_push.ref = None + await self.join_push.resend() + def _can_push(self): return self.socket.is_connected and self._joined_once