Skip to content
This repository was archived by the owner on Aug 21, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion realtime/_async/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,35 @@ async def _heartbeat(self) -> None:
ref=None,
)
await self.send(data)
await asyncio.sleep(self.hb_interval)
# Use max to avoid hb_interval=0 bugs etc
await asyncio.sleep(max(self.hb_interval, 15))
except websockets.exceptions.ConnectionClosed:
# If ConnectionClosed then is_connected == False
self.is_connected = False

if self.auto_reconnect:
logger.info("Connection with server closed, trying to reconnect...")
await self.connect()
# If auto_reconnect and connect() then is_connected == True
self.is_connected = True

## Apply the new socket to every channel and rejoin.
for topic, channel in self.channels.items():
logger.info(f"Rejoining to: {topic}")
channel.socket = self
await channel._rejoin()
# Wait before sending another phx_join message.
# Use max to avoid hb_interval=0 bugs etc
await asyncio.sleep(max(self.hb_interval, 15))

else:
# If ConnectionClosed and not auto_reconnect then is_connected == False
self.is_connected = False
logger.exception("Connection with the server closed.")
break
else:
# Everything went Ok then is_connected == True
self.is_connected = True

@ensure_connection
def channel(
Expand Down
Loading