Skip to content
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

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

Closed
Wyctus opened this issue Dec 14, 2020 · 12 comments
Closed

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

Wyctus opened this issue Dec 14, 2020 · 12 comments
Assignees
Labels
1.x 1.0 related issues Investigate

Comments

@Wyctus
Copy link

Wyctus commented Dec 14, 2020

This error started to happen to me regularly for a couple of weeks now. I can't tell the reason, seems to be totally random. Maybe it's a problem with Infura, since the error pops up on two different machines at the same time (they are running the same code).
My code is simply listening to some events on a some contracts. Sometimes it works for a day without any problem. But after it happens I can't reconnect for 30-60 minutes.
Looks pretty similar to #1646.

Expected behavior

The connection should stay open.

Actual behavior

It disconnects and can't reconnect for a long time.

Steps to reproduce the behavior

const subscribe_to_contract_events = async contract => {    
    contract.events.SomeEventName().on("data", async event => {
           // process the event
    });
}

for (const contract of contracts) {
    try {
        await subscribe_to_contract_events(contract);
    } catch (err) {
        console.error(err);
    }
}

The contracts contains around 400 elements.

Logs

Error: CONNECTION ERROR: Couldn't connect to node on WS.
    at Object.ConnectionError (/home/wyctus/p1/node_modules/web3-core-helpers/lib/errors.js:66:23)
    at Object.InvalidConnection (/home/wyctus/p1/node_modules/web3-core-helpers/lib/errors.js:36:21)
    at /home/wyctus/p1/node_modules/web3-providers-ws/lib/index.js:161:37
    at Map.forEach (<anonymous>)
    at WebsocketProvider._onClose (/home/wyctus/p1/node_modules/web3-providers-ws/lib/index.js:160:28)
    at W3CWebSocket._dispatchEvent [as dispatchEvent] (/home/wyctus/p1/node_modules/yaeti/lib/EventTarget.js:115:12)
    at W3CWebSocket.onClose (/home/wyctus/p1/node_modules/websocket/lib/W3CWebSocket.js:228:10)
    at WebSocketConnection.<anonymous> (/home/wyctus/p1/node_modules/websocket/lib/W3CWebSocket.js:201:17)
    at WebSocketConnection.emit (node:events:329:20)
    at WebSocketConnection.handleSocketClose (/home/wyctus/p1/node_modules/websocket/lib/WebSocketConnection.js:389:14)
    at TLSSocket.emit (node:events:341:22)
    at node:net:655:12
    at TCP.done (node:_tls_wrap:564:7) {
  code: 1011,
  reason: 'Internal response error'
}

Environment

Machine1:

  • OS: Manjaro 20.0
  • Node: v14.5.0
  • npm: 6.14.5
  • Web3: 1.3.0

Machine2:

  • OS: Debian 10
  • Node: v15.2.1
  • npm: 7.0.8
  • Web3: 1.3.0
@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. If you believe this was a mistake, please comment.

@github-actions github-actions bot added the Stale Has not received enough activity label Feb 13, 2021
@gabmontes
Copy link
Contributor

gabmontes commented Sep 3, 2021

This problem happens regularly. There is a hint of what could be happening in the Infura Community forums:

One thing to check is if your library supports automatic/manual Pong, and to make sure your context doesn’t cancel the client by timeout...

https://community.infura.io/t/internal-logs-subscription-error/2992/3

IMO the issue should be reopened.

cc/ @spacesailor24

@spacesailor24 spacesailor24 reopened this Sep 4, 2021
@spacesailor24 spacesailor24 added 1.x 1.0 related issues Investigate and removed Stale Has not received enough activity labels Sep 4, 2021
@spacesailor24
Copy link
Contributor

Thank you @Wyctus for making this issue, we've actually experienced this with our test suite and couldn't figure out why

Thank you @gabmontes for bringing this back from the dead 🧟

Have either of y'all tried this fix:

const Web3 = require('web3');
const util = require('util');

async function main(){
  const web3 = new Web3(new Web3.providers.WebsocketProvider(
    'wss://ropsten.infura.io/ws/v3/<infura-project-id>', // <-- Put your projectID here
    {
      clientConfig: {
        maxReceivedFrameSize: 100000000,
        maxReceivedMessageSize: 100000000,
      }
    }
  ));
  const block = await web3.eth.getBlock(599275, true);
  console.log(util.inspect(block))
}

main()
  .then(() => process.exit(0))
  .catch(err => {
    console.log(err);
    process.exit(1)
  });

Mentioned here

@Wyctus
Copy link
Author

Wyctus commented Sep 4, 2021

Thank you @spacesailor24 for the idea. I started to run my original code with your config. I will run it for a couple of hours to see what happens.

The error always happened really randomly, sometimes worked perfectly for 2-3 days, so I don't know what will happen now. If I don't experience the issue for a couple of hours, it doesn't mean it's gone.
I should run it for a couple of days, I guess, to be sure.

@Wyctus
Copy link
Author

Wyctus commented Sep 4, 2021

I finished an 11 hour long continous testing. No error so far. I will keep running the test tommorow.

@Wyctus
Copy link
Author

Wyctus commented Sep 5, 2021

@spacesailor24
Today I'm running the test again. On the initial startup the error immediately happened, so seems like this config doesn't fix it totally. After restart, everything works fine, I will keep running for a while.

Update: The test was running after the initial problem for 12 hours without any issue.

@spacesailor24
Copy link
Contributor

@Wyctus Thank you for the updates

@spacesailor24
Copy link
Contributor

Closing the issue for now, please reopen if the error persists

@hariomchetu
Copy link

hariomchetu commented Aug 4, 2022

Error: CONNECTION ERROR: Couldn't connect to node https://eth-goerli.g.alchemy.com/v2/API_KEY
at Object.ConnectionError (C:\Users\hariomkumars\Desktop\programs\testprogram\token\node_modules\web3-core-helpers\lib\errors.js:66:23)
at Object.InvalidConnection (C:\Users\hariomkumars\Desktop\programs\testprogram\token\node_modules\web3-core-helpers\lib\errors.js:36:21)
at HttpProvider.failed (C:\Users\hariomkumars\Desktop\programs\testprogram\token\node_modules\web3-providers-http\lib\index.js:136:25)
at processTicksAndRejections (internal/process/task_queues.js:93:5)

I'm facing this problem from two weeks. Any on can have solution then please tell me.
coming same issue when im using infura and alchemy

@godtaehee
Copy link

Me too. Anyone Help?

Below is error message.

InvalidConnection: host => new Error(CONNECTION ERROR: Couldn't connect to node ${host}.),
^
Error: CONNECTION ERROR: Couldn't connect to node https://public-node-api.klaytnapi.com/v1/baobab.

@anisurrahman072
Copy link

anisurrahman072 commented Nov 3, 2022

Use https instead of wss. It worked for me fine.
For your reference i used the core Etherium web3.js to create provider instance, wallet, everything. One important thing i used Alchemy for my Polygon Mumbai Testnetwork 🎉

@godtaehee
Copy link

Thanks, but I didn't use wss. I use the HttpProvider.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.x 1.0 related issues Investigate
Projects
None yet
Development

No branches or pull requests

6 participants