Skip to content

Fix Websocket reconnection stuck after network disruption - #59

Merged
aonemd merged 2 commits into
mainfrom
fix-reconnect
Dec 5, 2025
Merged

aonemd merged 2 commits into
mainfrom
fix-reconnect

Conversation

@aonemd

@aonemd aonemd commented Dec 4, 2025

Copy link
Copy Markdown
Member
  • Add isListening flag to track and restart the message listening loop
  • Tear down dead/stuck connections in connect() and create fresh ones
  • Call listen() when connection becomes ready to restart message receiving

- Add isListening flag to track and restart the message listening loop
- Tear down dead/stuck connections in connect() and create fresh ones
- Call listen() when connection becomes ready to restart message receiving
@aonemd aonemd changed the title Fix WebSocket reconnection after network disruption Fix Websocket reconnection stuck after network disruption Dec 5, 2025
@aonemd
aonemd merged commit 23b4f7f into main Dec 5, 2025
4 checks passed
@aonemd
aonemd deleted the fix-reconnect branch December 5, 2025 12:48
adhorodyski added a commit to callstack-internal/Expensify-App that referenced this pull request Aug 14, 2026
We ship NWWebSocket 0.5.7 with two bugs, both fixed upstream, and both
matching what our iOS clients do in production:

- A reconnect that can never succeed - pusher/NWWebSocket#59, in 0.5.8.
- Dead sockets that report themselves .ready - pusher/NWWebSocket#62, fixed
  in pusher/NWWebSocket#64, in 0.5.10.

PusherSwift 10.1.6 already asks for NWWebSocket '~> 0.5.7', so only
Podfile.lock was holding us at 0.5.7. Pinning the floor in the Podfile picks
both fixes up with no other movement. 0.5.7..0.5.10 touches one file and
changes no public API, so PusherSwift 10.1.6 links against it unchanged.
OldDot shares this pod via PusherSwiftWithEncryption, so it gets both fixes
too. Android is untouched.

Where it hits us. 1d query on start=2026-08-09T00:00:00Z
end=2026-08-10T00:00:00Z, deduplicated on (email, client timestamp):

  DISCONNECTED -> RECONNECTING   142,924 / 21,793 users = 6.56   100% iOS
  RECONNECTING -> DISCONNECTED    88,464 / 20,409 users = 4.34   100% iOS
  CONNECTING   -> DISCONNECTED    75,672 / 19,881 users = 3.81   100% iOS
  RECONNECTING -> CONNECTED       25,708 / 11,327 users = 2.27   90.4% iOS
  Socket presumed dead (iOS)      48,954 / 21,811 users = 2.24

Only 18.0% of retries reach CONNECTED - 4.6 failures per success - and
60.6% of active iOS users entered the loop that day.

Expect ReconnectApp to rise, not fall: a failed retry never re-subscribes,
so fixing the loop converts 88,464 silent failures into successful connects.

Why not bump @pusher/pusher-websocket-react-native to 1.3.5, which was the
previous approach here. The wrapper's 1.3.1..1.3.3 diff contains no source
files at all, only a podspec re-pin, and PusherSwift 10.1.6..10.1.10 changes
no socket code either - both fixes are in NWWebSocket and nowhere else. What
the bump does add is PusherSwift 10.1.9's swap of TweetNacl for
PusherTweetNacl, a fork of the same C library. PusherSwiftWithEncryption was
never published past 10.1.6, so OldDot stays on TweetNacl and both forks
collide in the HybridApp binary. Dropped for a pin that carries the fixes and
builds.

Also fixes a dead branch in our own error plumbing. Native passed
{data: {message}} with no `type`, while PusherConnectionManager gates its
error handler on `'type' in error`, so every native Pusher error was dropped
before any log call - 0 of 63,271 error lines carried a native user agent.
Routing them through WEB_SOCKET_ERROR makes the reconnect cause
attributable, which is what lets this change be measured rather than assumed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
adhorodyski added a commit to callstack-internal/Expensify-App that referenced this pull request Aug 14, 2026
We ship NWWebSocket 0.5.7 with two bugs, both fixed upstream, and both
matching what our iOS clients do in production:

- A reconnect that can never succeed - pusher/NWWebSocket#59, in 0.5.8.
- Dead sockets that report themselves .ready - pusher/NWWebSocket#62, fixed
  in pusher/NWWebSocket#64, in 0.5.10.

PusherSwift 10.1.6 already asks for NWWebSocket '~> 0.5.7', so only
Podfile.lock was holding us at 0.5.7. Pinning the floor in the Podfile picks
both fixes up with no other movement. 0.5.7..0.5.10 touches one file and
changes no public API, so PusherSwift 10.1.6 links against it unchanged.
OldDot shares this pod via PusherSwiftWithEncryption, so it gets both fixes
too. Android is untouched.

Where it hits us. 1d query on start=2026-08-09T00:00:00Z
end=2026-08-10T00:00:00Z, deduplicated on (email, client timestamp):

  DISCONNECTED -> RECONNECTING   142,924 / 21,793 users = 6.56   100% iOS
  RECONNECTING -> DISCONNECTED    88,464 / 20,409 users = 4.34   100% iOS
  CONNECTING   -> DISCONNECTED    75,672 / 19,881 users = 3.81   100% iOS
  RECONNECTING -> CONNECTED       25,708 / 11,327 users = 2.27   90.4% iOS
  Socket presumed dead (iOS)      48,954 / 21,811 users = 2.24

Only 18.0% of retries reach CONNECTED - 4.6 failures per success - and
60.6% of active iOS users entered the loop that day.

Expect ReconnectApp to rise, not fall: a failed retry never re-subscribes,
so fixing the loop converts 88,464 silent failures into successful connects.

Why not bump @pusher/pusher-websocket-react-native to 1.3.5, which was the
previous approach here. The wrapper's 1.3.1..1.3.3 diff contains no source
files at all, only a podspec re-pin, and PusherSwift 10.1.6..10.1.10 changes
no socket code either - both fixes are in NWWebSocket and nowhere else. What
the bump does add is PusherSwift 10.1.9's swap of TweetNacl for
PusherTweetNacl, a fork of the same C library. PusherSwiftWithEncryption was
never published past 10.1.6, so OldDot stays on TweetNacl and both forks
collide in the HybridApp binary. Dropped for a pin that carries the fixes and
builds.

Also fixes a dead branch in our own error plumbing. Native passed
{data: {message}} with no `type`, while PusherConnectionManager gates its
error handler on `'type' in error`, so every native Pusher error was dropped
before any log call - 0 of 63,271 error lines carried a native user agent.
Routing them through WEB_SOCKET_ERROR makes the reconnect cause
attributable, which is what lets this change be measured rather than assumed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.

1 participant