python realtime silent timeout issue
I have a long-running, asynchronous Python service (using
Implementation:
My implementation follows this pattern:
The Realtime connection works perfectly for a while, but eventually (often after several hours or a day) it seems to silently time out or disconnect. The service doesn't crash and no exceptions are raised, but it simply stops receiving any new database change events.
Question:
What is the recommended, robust pattern for handling these silent timeouts with
asyncio) that runs inside a Docker container. Its primary job is to listen for database changes.Implementation:
My implementation follows this pattern:
- On service startup, I create a single, global
AsyncClientinstance usingawait acreate_client(...). - I then immediately subscribe to
INSERTandUPDATEevents on a specific table using the Realtime client: - The callback functions (
my_async_..._handler) areasyncand useasyncio.create_taskto process events without blocking the listener.
The Realtime connection works perfectly for a while, but eventually (often after several hours or a day) it seems to silently time out or disconnect. The service doesn't crash and no exceptions are raised, but it simply stops receiving any new database change events.
Question:
What is the recommended, robust pattern for handling these silent timeouts with
supabase-py's async Realtime client? Is there a built-in auto-reconnect mechanism that I'm not implementing correctly, or what would be the idiomatic solution for a heartbeat/health check and resubscribe logic to ensure the connection stays alive?