I have a Node JS application which connects to a Geth Node using the Web3WsProvider which under the hood uses W3CWebSocket.

The app starts and connects to the node and is set mostly to make read only calls to the node. This works fine, except that at exactly every 2 hours, the WebSocket connection to the node resets and the app then needs to reconnect. While I have configured the Web3WsProvider to automatically reconnect, any connection drop is undesirable as during this moment there are possible events that my application needs to capture and could potentially miss.

I am unable to find anything in the source code of the Web3WsProvider or W3CWebSocket libraries that I am using that would cause this connection reset to occur every 2 hours so it would appear it is Geth that is causing this connection reset.

Is there something that I can do to avoid Geth resetting the WebSocket connection every 2 hours like this?

1 Answer 1


So it turns out that this is a specific issue with Amazon Managed Blockchain (AMB) where the Geth node was running. This appears to be the same 2-hour hard limit “Connection duration for WebSocket API” of AWS API Gateway beneath. Note that I've confirmed this with an AWS Support Engineer.

So a simple workaround, when faced with a similar condition to this (either using AMB or another provider), is to re-establish a new connection just before, in setTimeout() and handle dupe events, or ws.onclose() with potentially missed events.

Alternatively, just switch providers to one that does not have the 2-hour hard limit such as QuikNode or even by running your own private Geth node.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.