[Ropsten] - CONNECTION ERROR: Couldn't connect to node on WS

Hi everyone, I have been running a job which runs every minute and checks for transactions against a set of contracts.

I run the same code against mainnet, rinkeby & ropsten but about 3 days ago ropsten started to kick back an error.

Error: CONNECTION ERROR: Couldn't connect to node on WS.

Code uses a websocket connection, we utilise web3js.1.0.37-beta

new Web3(new Web3.providers.WebsocketProvider(`wss://${network}.infura.io/ws/v3/${INFURA_API_KEY_V3}`));

It looks to be failing on the actual connection, I am running this in the hosted environment on google cloud and the job runs successfully for other networks.

Any ideas?

Many thanks


Hey James,

Are you still experiencing this issue?

Hello James,

I just ran a simple websocket test to get protocol version on ropsten, and I’m getting a connection and a response. Is there any more details you can provide? I have run into issues on firefox not being able to connect due to a header issues and well as certain version of web3js. (I tested on web3js.1.0.33)

Hi Guys, I have added more logging and still get this issue, here is my log out:

info: Connecting to INFURA web socket provider [wss://ropsten.infura.io/ws/v3/<MY_API_KEY>]
info: TXS Parser - Logging all TXS on network [ropsten]
info: TXS Parser - Last network block number of [4887580] for network [ropsten]
Preformatted textinfo: TXS Parser - Last processed block [4728912] for network [ropsten]
error: TXS Parser Error - failed to handle with block [4728956] for network [ropsten] Error: CONNECTION ERROR: Couldn't connect to node on WS.
at Object.InvalidConnection (/Users/jamesmorgan/Dropbox/workspace-blockrocket/known-origin-serverless-api/functions/node_modules/web3-core-helpers/src/errors.js:35:16)
at WebsocketProvider._timeout (/Users/jamesmorgan/Dropbox/workspace-blockrocket/known-origin-serverless-api/functions/node_modules/web3-providers-ws/src/index.js:249:48)
at W3CWebSocket.connection.onclose (/Users/jamesmorgan/Dropbox/workspace-blockrocket/known-origin-serverless-api/functions/node_modules/web3-providers-ws/src/index.js:149:15)
at W3CWebSocket._dispatchEvent [as dispatchEvent] (/Users/jamesmorgan/Dropbox/workspace-blockrocket/known-origin-serverless-api/functions/node_modules/yaeti/lib/EventTarget.js:107:17)
at W3CWebSocket.onClose (/Users/jamesmorgan/Dropbox/workspace-blockrocket/known-origin-serverless-api/functions/node_modules/websocket/lib/W3CWebSocket.js:228:10)
at WebSocketConnection.<anonymous> (/Users/jamesmorgan/Dropbox/workspace-blockrocket/known-origin-serverless-api/functions/node_modules/websocket/lib/W3CWebSocket.js:201:17)
at emitTwo (events.js:126:13)
at WebSocketConnection.emit (events.js:214:7)
at WebSocketConnection.drop (/Users/jamesmorgan/Dropbox/workspace-blockrocket/known-origin-serverless-api/functions/node_modules/websocket/lib/WebSocketConnection.js:473:14)
at /Users/jamesmorgan/Dropbox/workspace-blockrocket/known-origin-serverless-api/functions/node_modules/websocket/lib/WebSocketConnection.js:301:18
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickCallback (internal/process/next_tick.js:180:9)
error: TXS Parser Error Error: CONNECTION ERROR: Couldn't connect to node on WS.
info: Execution took 42600 ms, user function completed successfully

The code is being run for a serverless function on google cloud so not in a browser, I am using latest web3 and V3 Infura API key.

It looks like this actual line that is failing from web3js is this:

const blockData = await web3.eth.getBlock(block, true);

Block being the 4728956

Is there some additional steps/config that you’d like me to try and log out to help diagnose this.

Whats strange that the same code runs on rinkeby and mainnet with no issues.

Let me know if this is useful

Thanks again - awesome product :+1:

Hello James,

I just did a simple test to get blockbyNumber on ropsten for block 4728956

xxxxxxxx~ Jee$ wscat -c wss://ropsten.infura.io/ws
    connected (press CTRL+C to quit)
    > {"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["0x48287C", true],"id":1}
    < {"jsonrpc":"2.0","id":1,"result":{"difficulty":"0x591db0a6","extraData":"0xd883010811846765746888676f312e31312e31856c696e7578","gasLimit":"0x7cd797","gasUsed":"0x7cb149","hash":"0x3f427e6f3b7d19cbb8524144dccfa333c0b30a61cf309d15f2786a40908f3b5a","

As you can see, I am able to connect to ropsten and retrieve the mentioned block. Can you try running the above request? (you need to install wscat)

Just tested this locally and seems to work with wscat but not when used in web3js - I found this on github which sounds related https://github.com/ethereum/web3.js/issues/1646

I have also found that adding this config fixed it - taken direct from #1217

  clientConfig: {
    maxReceivedFrameSize: 100000000,
    maxReceivedMessageSize: 100000000,