I use websocket (ws) coneection to Infura node
web3 = new Web3(new Web3.providers.WebsocketProvider("wss://ropsten.infura.io/ws"));
sometimes it's works fine or sometimes it give error on console :
Error: CONNECTION ERROR: Couldn't connect to node on WS.
Uncaught (in promise) Error: CONNECTION ERROR: Couldn't connect to node on WS.
I am not getting why its happening.
Can you determine when exactly this is happening? It's a bit hard to reproduce it this way.
I got the same issue, my code works with provider: "wss://ropsten.infura.io/ws" (testnet), but it doesn't work with "wss://mainnet.infura.io/ws".
I use the code in introduction page https://infura.io/docs/wss/introduction
I also had the same issue with "wss://rinkeby.infura.io/ws".
added some other details for same issue found here at https://github.com/INFURA/infura/issues/140
I'm having the same issue (using Kovan WS endpoint). It's extremely sporatic... About 25% of the time it works fine, and the other 75% it throws the CONNECTION ERROR.
I'll run my program once and it will fail, and then again with no changes and it will fail.
Hard to see if this is an issue with Infura, or somewhere lower in the stack like the WS driver.
I also get this almost exclusive failing with the latest version of web3 1.0.37 - originally I thought it was an issue with Infura but then found this issue, any ideas on the solution - this is the ticket I raised with Infura https://community.infura.io/t/ropsten-connection-error-couldnt-connect-to-node-on-ws/272/5
I have also found that adding this config fixed it - taken direct from https://github.com/ethereum/web3.js/issues/1217
{
clientConfig: {
maxReceivedFrameSize: 100000000,
maxReceivedMessageSize: 100000000,
}
}
@jamesmorgan I've refactored the web3 providers and especially the WebsocketProvider (PR #2000). I will release this PR within the next days and probably this issue got fixed with it. I can't see anything that Web3.js is doing which could have an impact on establishing a connection.
No further issue mentions for over a year, will close for now. Feel free to reopen.
Most helpful comment
I got the same issue, my code works with provider: "wss://ropsten.infura.io/ws" (testnet), but it doesn't work with "wss://mainnet.infura.io/ws".
I use the code in introduction page https://infura.io/docs/wss/introduction