Skip to content

Conversation

@spencerstock
Copy link
Contributor

@spencerstock spencerstock commented Jun 17, 2025

Summary

This set of fixes specifically targets reliability on mobile-mobile flows. It speeds up and fixes things in the reconnect process for our walletlink websockets.

Connection Management:

  • Added WebSocket instance tracking to prevent event handling from stale connections
  • Fresh WebSocket creation on reconnection instead of reusing failed instances
  • Instance management to enable quicker + more reliable reconnections
  • Reconnection
    • backoff (0s first attempt, then 3s delay)
    • Prevent concurrent reconnection attempts

Heartbeat:

  • Fixed heartbeat timer management by properly clearing intervals on disconnect
  • Added connection state check before sending heartbeats to prevent errors
  • Reset lastHeartbeatResponse on disconnect to prevent false timeout detection on reconnection
  • Send immediate heartbeat after connection establishment for faster connection validation

Browser Event Handling:

  • Added visibility change and focus event handlers to detect when users returns to the app
  • Tighten up reconnect when tab/window regains focus

How did you test your changes?

manually

Also tested for regressions on long-idle desktop chrome tabs (Will's service worker fix):

  • built locally
  • Run the app in an incognito Chrome window
  • Connect via WL, confirm you receive and can sign the message request
  • Then, leave the chrome tab open for 10mins without interacting with it (don't open a new tab)
  • Come back to the tab and try initiating a new signing request
  • Confirm you can receive an sign the message request

Also built locally and tested the playground, extension, desktop to mobile

Failure 1 (before fixes)

commercefail1.mp4

Failure 2 (before fixes)

commercefail2.mp4

Success with fixes

commercesuccess1.mp4

@cb-heimdall
Copy link
Collaborator

cb-heimdall commented Jun 17, 2025

✅ Heimdall Review Status

Requirement Status More Info
Reviews 3/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
Sum 1

@spencerstock spencerstock force-pushed the spencer/websocket-refactor branch 5 times, most recently from 70f5fe1 to 186d887 Compare June 17, 2025 21:57
@spencerstock spencerstock force-pushed the spencer/websocket-refactor branch from 186d887 to 646466a Compare June 17, 2025 22:15
@spencerstock spencerstock marked this pull request as ready for review June 17, 2025 22:29
throw new Error('webSocket object is not null');
}
if (this.isDisconnecting) {
throw new Error('WebSocket is disconnecting, cannot reconnect on same instance');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: reconnect => connect for consistency with the function name we're in

Copy link
Contributor

@fan-zhang-sv fan-zhang-sv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Tested locally against both spencer's hosted commerce site + locally hosted playground

  1. desktop to mobile
  2. mobile to mobile

tested delaying approval for 10+ second, all test cases went thru, so lit

const address = await this.cipher.decrypt(encryptedEthereumAddress);
this.listener?.accountUpdated(address);
} catch {
// Had error decrypting
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we output these errors anywhere? Failing silently is a bit concerning

@fan-zhang-sv fan-zhang-sv merged commit 2f387e5 into master Jun 23, 2025
8 checks passed
@fan-zhang-sv fan-zhang-sv deleted the spencer/websocket-refactor branch June 23, 2025 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

6 participants