Skip to content

Replay subscriptions when reconnecting in websocket #3772

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 3, 2025

Conversation

hazelnutcloud
Copy link
Contributor

Fixes #3771

This PR fixes the issue where WebSocket subscriptions are lost after a reconnection and not automatically restored. When using the WebSocket transport with reconnect: true, subscriptions created via watchBlockNumber, watchContractEvent, etc. would silently stop working after the connection dropped and reconnected.

- Store request body in callback map for replay capability
- Clear subscriptions and replay pending requests on reconnect
- Fix reconnection logic to iterate over subscriptions instead of requests
- Store request body in subscriptions for proper reconnection
- Remove body from requests map to avoid duplication
- Ensure subscriptions can be properly restored after reconnect
Copy link

changeset-bot bot commented Jul 2, 2025

🦋 Changeset detected

Latest commit: d5c33ea

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
viem Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Jul 2, 2025

@hazelnutcloud is attempting to deploy a commit to the Wevm Team on Vercel.

A member of the Team first needs to authorize it.

@hazelnutcloud hazelnutcloud changed the title Fix/ws subscriptions Replay subscriptions when reconnecting in websocket Jul 2, 2025
@jxom jxom merged commit d79fb7e into wevm:main Jul 3, 2025
11 of 25 checks passed
@github-actions github-actions bot mentioned this pull request Jul 3, 2025
Copy link

@Amnat-auyana1998 Amnat-auyana1998 left a comment

Choose a reason for hiding this comment

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

@amnatxx199x

@Amnat-auyana1998
Copy link

@Amnat-auyana1998

@hazelnutcloud hazelnutcloud deleted the fix/ws-subscriptions branch July 7, 2025 09:21
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.

WebSocket subscriptions are lost after reconnection and not automatically restored
3 participants