powersync-js icon indicating copy to clipboard operation
powersync-js copied to clipboard

[PowerSyncStream] [Error: Could not connect to PowerSync instance: undefined] - keeps getting logged when offline

Open rahulshettykcf opened this issue 7 months ago • 3 comments

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:

  1. Unnecessary error logs
  2. Difficulty identifying actual issues in logs due to noise

rahulshettykcf avatar May 21 '25 14:05 rahulshettykcf

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.

michaelbarnes avatar May 21 '25 22:05 michaelbarnes

Hello @michaelbarnes,

Thank you for your response.

Image

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

rahulshettykcf avatar Jun 07 '25 03:06 rahulshettykcf

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.

simolus3 avatar Jun 10 '25 08:06 simolus3