-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Web3 throws if a connection is lost #bug #1025
Comments
This is the only issue that's stopping the next phase of my project. Otherwise, [email protected] is amazing :) One idea I had for a workaround is to run everything to do with web3 in a separate process I haven't tested it, but it should work. (if you really want this to work ASAP) |
We currently have a fork that fixes this, working on a PR with @hudgins |
I think it‘s not a bug,Just we need to monitor the events of websocket,@web3.js should provide the events of websocket to us,Let's know about websocket status,e.g.:'CONNECTING','OPEN','CLOSING','CLOSED'. |
error in npm start connection not open on send() |
I am also facing this error. See the below message connection not open on send() can you please help. const Web3 = require('web3'); I am using [email protected] |
facing same issue in [email protected] , |
tried with this still does not work for me |
I'll close this issue because I cant reproduce this behavior. Please create a new one if this behaviour still occurs. |
Do you start Ethernode on local machine? Connecting to socket that perfomed on local machine is easily but on docker container is not. |
This issue is still occuring for me using an Infura node |
Same. Looks like infura closes idle's connections when too many connected. We'd need a retry mechanism. |
Infura's WebSocket FAQ states:
This can be achieved using Web3js by passing in const provider = new Web3.providers.WebsocketProvider(
url,
{
// @ts-ignore
clientConfig: {
keepalive: true,
keepaliveInterval: 60000 // milliseconds
}
}
);
The |
I'm still seeing this issue (seems like once every 48hrs or so), even with @naddison36's suggestion. 🙁 I have to restart the application to get it to reconnect. Some way to reconnect automatically on connection closed is desperately needed. const provider = new Web3.providers.WebsocketProvider(PROVIDER_WS, {
clientConfig: {
keepalive: true,
keepaliveInterval: 60000,
},
reconnect: {
auto: true,
delay: 2500,
onTimeout: true,
}
}) |
@andrewda I think your config will only attempt to reconnect once after 2.5 seconds. But to answer your question, you should be able to catch the connection close with the provider.on("close", err => {
logger.error(`WebSocket connection closed. Error code ${err.code}, reason "${err.reason}"`);
// invert your own error handling here
}); |
@naddison36 I believe the default ( Thanks for the suggestion on catching the connection close, though. I'll give that a shot! |
Did the reconnect option solve your problem? |
When using Web3 and connecting through websockets & subscriptions, if the connection drops (ex. Node goes offline), the entire application throws. This is not very developer friendly, as it risks taking down the entire application. There doesn't appear a great way to encapsulate this inside a try/catch or otherwise.
Error:
To reproduce:
Now, restart your websocket node, and see if you can keep the application from exiting.
The text was updated successfully, but these errors were encountered: