Skip to content

fix: reconnect past connection timeout - #1874

Merged
isekovanic merged 1 commit into
release-v10from
fix/reconnect-past-timeout
Sep 17, 2026
Merged

isekovanic merged 1 commit into
release-v10from
fix/reconnect-past-timeout

Conversation

@isekovanic

@isekovanic isekovanic commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

CLA

  • I have signed the Stream CLA (required).
  • Code changes are tested

Description of the changes, What, Why and How?

Cold starting an app with no network and staying offline for longer than defaultWSTimeout (15s) permanently killed reconnection. Restoring connectivity after that point never brought the socket back — the UI sat on "Searching for Network" indefinitely.

So, connectUser was tearing down its own retry loop.

  1. Offline cold start: _connect() fails, and onerror/onclose start the _reconnect() backoff loop. That loop is what used to recover.
  2. 15s later _waitForHealthy times out and throws {"message":"initial WS connection could not be established","isWSFailure":true}, so connectUser rejects, even though the retry loop behind it is perfectly healthy.
  3. Its catch ran persistUserOnConnectionFailure ? closeConnection() : disconnectUser(). Both call wsConnection.disconnect(), which sets isDisconnected = true.
  4. Connectivity returns, the UI SDK forwards it via onlineStatusChanged('online'), and _reconnect() bails with Aborting reconnect: disconnect() was called. forever.

This did not bite before v10 because the two isDisconnected guards in _connect / _reconnect were ANDed with options.enableWSFallback, which nothing ever set. Verified against a built v9.53.0: enableWSFallback is undefined, so both guards were dead code and the retry loop always survived the teardown. #1760 removed the WS fallback along with the option, leaving the guards unconditional and turning a previously inert cleanup into a permanent kill switch.

How. On the persistUserOnConnectionFailure path, only close the connection when the failure is not a WebSocket failure. A terminal failure, so a rejected token, bad API key or something I can't think of still cleans up, so nothing is left retrying against a connection that cannot succeed. A network failure is left alone, because StableWSConnection is still retrying and owns recovery from there.

The non persist branch keeps calling disconnectUser(), so with no user retained there is nothing to reconnect as, and the application is expected to call connectUser again.

Changelog

  • Fixed reconnection never being re-established after an app was cold-started without a network
    connection for longer than the WebSocket connect timeout.

@isekovanic
isekovanic merged commit 2004a83 into release-v10 Sep 17, 2026
5 of 7 checks passed
@isekovanic
isekovanic deleted the fix/reconnect-past-timeout branch September 17, 2026 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants