-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed
Description
Check existing issues
- I checked there isn't already an issue for the bug I encountered.
Viem Version
2.31.7
Current Behavior
When the WebSocket transport loses connection, the reconnection logic can cause it to open multiple connections. It's possible to get into a situation where neither the reconnection limit (default 5) nor the delay between new connection attempts are respected, and the client ends up creating lots of open WebSocket connections.
Expected Behavior
- The WebSocket transport should only attempt to reconnect up to the specified number of times and space out each connection attempt by the specified delay.
- There should only be one WebSocket connection (per server and settings) that should be shared by all clients using the WebSocket transport.
Steps To Reproduce
Steps to reproduce:
- clone the forked repo at
alvrs/websocket-repro pnpm install && pnpm buildat rootpnpm install && pnpm dev --forceat/environments/vite- open
http://localhost:5173/ - open Network inspector
- turn "Throttling" to "Offline"
- wait for reconnection logic to kick in
- observe many WebSocket connection attempts to
rpc.redstonechain.com - turn "Throttling" back to "No throttling"
- observe multiple open WebSocket connections
CleanShot.2025-07-16.at.15.49.31.mp4
Link to Minimal Reproducible Example
Anything else?
We also experience this situation when leaving the browser tab in the background for a while. The network throttling approach described above is how we can consistently reproduce it.
Metadata
Metadata
Assignees
Labels
No labels