-
Notifications
You must be signed in to change notification settings - Fork 5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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, web3@1.0.0 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 web3@1.0.0.beta34 |
facing same issue in web3@beta.34 , |
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: