Skip to content

Commit

Permalink
fix: ensure socket is closed (#3313)
Browse files Browse the repository at this point in the history
* fix: ensure socket is closed

* socket client

* Create yellow-clocks-brake.md

---------

Co-authored-by: jxom <[email protected]>
  • Loading branch information
holic and jxom authored Feb 6, 2025
1 parent 149d406 commit 15bec5d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/yellow-clocks-brake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"viem": patch
---

Closed socket on cleanup for RPC transport.
6 changes: 6 additions & 0 deletions src/utils/rpc/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ export async function getSocketRpcClient<socket extends {}>(
requests.clear()
subscriptions.clear()

// Make sure socket is definitely closed.
socketClient?.close()

// Attempt to reconnect.
if (reconnect && reconnectCount < attempts)
setTimeout(async () => {
Expand All @@ -163,6 +166,9 @@ export async function getSocketRpcClient<socket extends {}>(
requests.clear()
subscriptions.clear()

// Make sure socket is definitely closed.
socketClient?.close()

// Attempt to reconnect.
if (reconnect && reconnectCount < attempts)
setTimeout(async () => {
Expand Down

0 comments on commit 15bec5d

Please sign in to comment.