How to close a websocket connection? #1401
Unanswered
James-Unicrypt
asked this question in
Q&A
Replies: 2 comments 1 reply
-
You can use the // Once the promise resolves, the connection should be destroyed. If the
// provider was still connecting, this will stall until the connection has started
// or failed, then this method will resolve
await websocketProvider.destroy(); |
Beta Was this translation helpful? Give feedback.
0 replies
-
(moving to discussion) |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello!
I'm relying on etherjs to run frequent cron jobs back end. Im using a ethers.providers.WebSocketProvider and storing the provider globally. It seems sometimes this provider loses connection (after 2 days or so, and fails to reconnect thereafter)
I used to then have a one-day recurring cron job that resets the global provider e.g.
globalProvider = new ethers.providers.WebSocketProvider('URL') // overwrite old provider
The problem is with time this was leading to a ton of open but dead socket connections to my node which eventually causes it to lock up. How can I drop a provider connection properly? I cant seem to find this in the docs and there is no provider.close() method?
Beta Was this translation helpful? Give feedback.
All reactions