Open etzelc opened 1 month ago
I have the same issue, and it appears a lot of people are. Can the devs please provide an answer or workaround for this? The library unfortunately is not usable because of this disconnection.
Here is pseudocode of the workaround I am using successfully. auto_reconnect
is set to false
:
client = AsyncRealtimeClient(f"{url}/realtime/v1", key, auto_reconnect=False)
# Retry logic to manage reconnections within a set limit
while connection_loss_counter <= MAX_RECONNECTS:
try:
await client.connect()
channel = client.channel("the-channel")
channel.on_postgres_changes( ... ).subscribe(on_subscribe_callback)
try:
await client.listen()
finally:
# Calculate connection_loss_counter for retry logic (it is using a time window approach)
record_connection_loss()
except Exception:
# Continue the retry loop
continue
If too many exceptions occur (e.g., due to connection loss), additional mechanisms are executed after the loop to handle the situation.
How does setting auto_reconnect to false fix your issue, out of curiosity?
With auto_reconnect
to false
I don't use the broken reconncect logic, but handle it myself. listen()
throws an exception if the connection is lost and the loop re-establishes everything.
Bug report
Describe the bug
The
auto_reconnect
feature, which was fixed in PR #203, is not functioning as expected. When the connection to the realtime server is lost and reconnected usingauto_reconnect = true
, the client successfully rejoins the channel but does not resubscribe to thepostgres_changes
events.To Reproduce
An extracted version of the code setup:
Expected behavior
After the connection is automatically reestablished, all postgres_changes events should be resubscribed.
Log
2024-09-30T13:08:13.712427114Z
nopostgres_changes
are sent to the realtime server. On the first connect at2024-09-30T13:05:21.388617410Z
they have been sent.INFO: Channel phoenix not found
message appears repeatedly (is this related to the heartbeat?). It becomes a bit overwhelming as it floods the logs. I'm connecting to a Supabase cloud instance. Is there any configuration I need to set up to ensure this channel exists?System information