-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Description
Check existing issues
- I checked there isn't already an issue for the bug I encountered.
Viem Version
2.37.6
Current Behavior
If you start watching for new block numbers, using a WebSocket
transport, a PublicClient
, and watchBlockNumber
, and there is a connection failure and then the connection is restored, and after that you stop watching and then start watching again, you will receive duplicate numbers
Expected Behavior
The onBlockNumber
callback receives the same number only once
Steps To Reproduce
createPublicClient
usingwebSocket
const unwatch = watchBlockNumber({ onBlockNumber: someCallback });
- Disconnect from the Internet
- Wait a couple of minutes
- Reconnect to the Internet and wait for a new block number to be received
unwatch()
watchBlockNumber({ onBlockNumber: someOtherCallback });
someOtherCallback
will now (incorrectly) be called twice for the same block numbers
Link to Minimal Reproducible Example
https://github.com/oskarlh/viemwatchbug
Anything else?
Node v22.17 on MacOS 15.6.1.
In an application I have observed more than just duplication, with the same number being received three or even four times. It seemed to happen more frequently when I connected through a VPN.
Metadata
Metadata
Assignees
Labels
No labels