[PowerSyncStream] [Error: Could not connect to PowerSync instance: undefined] - keeps getting logged when offline
Issue Description
When the device loses internet connection (goes offline), PowerSync Stream continuously attempts to reconnect, generating error logs:
(NOBRIDGE) ERROR [PowerSyncStream] [Error: Could not connect to PowerSync instance: undefined]
(NOBRIDGE) DEBUG [PowerSyncStream] Streaming sync iteration started
(NOBRIDGE) DEBUG [PowerSyncStream] Requesting stream from server
https://github.com/powersync-ja/powersync-js/blob/38d36e2648b584db9a92e52b1fb4658e086fa1c0/packages/common/src/client/sync/stream/AbstractRemote.ts#L293
Expected Behavior
PowerSync should detect offline state and gracefully pause streaming attempts until connectivity is restored, rather than continuously logging errors.
Actual Behavior
The library repeatedly attempts to establish a connection despite the device being offline, resulting in:
- Unnecessary error logs
- Difficulty identifying actual issues in logs due to noise
Hey @rahulshettykcf thanks for the insights, can you expand on what you mean by "PowerSync should detect offline state and gracefully pause streaming", specifically the pause part.
We added the retryDelayMs and crudUploadThrottleMs options to the connect method that allows you specify a delay as to how frequently the uploadData function will be called. This might be useful given what you're after.
Hello @michaelbarnes,
Thank you for your response.
As you can see in the GIF, I keep getting Error: Could not connect to PowerSync instance: undefined
In the terminal, it would look like
(NOBRIDGE) DEBUG [PowerSyncStream] Streaming sync iteration started
(NOBRIDGE) DEBUG [PowerSyncStream] Requesting stream from server
(NOBRIDGE) ERROR [PowerSyncStream] [Error: Could not connect to PowerSync instance: undefined]
(NOBRIDGE) DEBUG [PowerSyncStream] Streaming sync iteration started
(NOBRIDGE) DEBUG [PowerSyncStream] Requesting stream from server
(NOBRIDGE) ERROR [PowerSyncStream] [Error: Could not connect to PowerSync instance: undefined]
(NOBRIDGE) DEBUG [PowerSyncStream] Streaming sync iteration started
(NOBRIDGE) DEBUG [PowerSyncStream] Requesting stream from server
(NOBRIDGE) ERROR [PowerSyncStream] [Error: Could not connect to PowerSync instance: undefined]
(NOBRIDGE) DEBUG [PowerSyncStream] Streaming sync iteration started
(NOBRIDGE) DEBUG [PowerSyncStream] Requesting stream from server
(NOBRIDGE) ERROR [PowerSyncStream] [Error: Could not connect to PowerSync instance: undefined]
(NOBRIDGE) DEBUG [PowerSyncStream] Streaming sync iteration started
(NOBRIDGE) DEBUG [PowerSyncStream] Requesting stream from server
(NOBRIDGE) ERROR [PowerSyncStream] [Error: Could not connect to PowerSync instance: undefined]
(NOBRIDGE) DEBUG [PowerSyncStream] Streaming sync iteration started
(NOBRIDGE) DEBUG [PowerSyncStream] Requesting stream from server
(NOBRIDGE) ERROR [PowerSyncStream] [Error: Could not connect to PowerSync instance: undefined]
I have to keep dismissing it as it keeps blocking me from pressing the buttons at the bottom. I think it's established that we are offline. Shouldn't the instance stop connecting to the server or streaming when offline?
Is it me doing something wrong to cause this issue? Happy to hear your thoughts
Shouldn't the instance stop connecting to the server or streaming when offline?
At the moment, there's nothing in our SDKs that would do a connectivity check and skip connection attempts while offline. The SDK will keep trying to connect with the configured retry delay. The error being logged is part of the recovery strategy, but I think you can configure the logger to ignore that message.
You can also listen for the connectivity status yourself and call connect() / disconnect() at appropriate times to avoid this.