Skip to content

fix: do not reconnect on intentional socket close#4601

Merged
jxom merged 4 commits into
wevm:mainfrom
o19k:fix/websocket-close-reconnect
May 17, 2026
Merged

fix: do not reconnect on intentional socket close#4601
jxom merged 4 commits into
wevm:mainfrom
o19k:fix/websocket-close-reconnect

Conversation

@o19k
Copy link
Copy Markdown
Contributor

@o19k o19k commented May 12, 2026

Summary

Calling socketClient.close() triggers the underlying socket.close(), which fires the onClose callback, which calls attemptReconnect(). This causes the socket to reconnect even when the caller explicitly wanted to close it — resulting in the node process never exiting.

Root cause: attemptReconnect() had no way to distinguish between an intentional close and an unexpected socket drop.

Fix: Added an intentionallyClosed flag (closure-scoped, mirrors the existing reconnectInProgress pattern). Set to true in socketClient.close() before calling socket.close(). Checked in attemptReconnect() to skip reconnection.

Fixes #4378

Test plan

  • reconnect on socket-level close — verifies unexpected socket drops still trigger reconnect
  • does not reconnect on intentional close — verifies socketClient.close() no longer reconnects
  • close does not reconnect (webSocket integration test) — end-to-end with a real WebSocket

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 12, 2026

🦋 Changeset detected

Latest commit: e04dd9b

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

@vercel
Copy link
Copy Markdown

vercel Bot commented May 13, 2026

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

A member of the Team first needs to authorize it.

jxom added 2 commits May 17, 2026 19:34
Also clarifies the changeset wording — the previous wording read as
the opposite of the fix.
@jxom jxom merged commit 449c5f6 into wevm:main May 17, 2026
2 of 3 checks passed
@github-actions github-actions Bot mentioned this pull request May 17, 2026
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.

unable to close websocket

2 participants