Linch1 / WeChartWeb3

Build a poocoin clone, scrape all the prices from pancakeswap or any other similar dex, build an historical record and offer an api to your users.
114 stars 77 forks source link

Error: connection not open on send() #10

Closed etulikov closed 2 years ago

etulikov commented 2 years ago

I have this error on my production server when run npm run scraper, but on local all good. Can you help?

Linch1 commented 2 years ago

Hello :) , can you paste more info ? like all the error traceback log

Is possible that you are missing the .env on the server ?

etulikov commented 2 years ago

@Linch1 My .env

PROVIDER_WSS=wss://bsc.getblock.io/mainnet/?api_key=MY_API_CODE PROVIDER_HTTPS=https://bsc.getblock.io/mainnet/?api_key=MY_API_CODE MONGO_URL=MY_DB_CONNECTION_STRING PORT=5010 WRITE_TO_DB_SECONDS=60 FRONTEND_URL=["http://localhost:5005", "http://localhost:5003"]

Every 2-3 hours scraper failed and pm2 restart it. So sometimes it works well, but sometime right after start logs shows next error:

Detected new log undefined Error: connection not open on send() at Object.ConnectionError (/Users/etulikov/Projects/datameta/worker/node_modules/web3-core-helpers/lib/errors.js:66:23) at Object.ConnectionNotOpenError (/Users/etulikov/Projects/datameta/worker/node_modules/web3-core-helpers/lib/errors.js:49:21) at /Users/etulikov/Projects/datameta/worker/node_modules/web3-providers-ws/lib/index.js:155:37 at Map.forEach () at WebsocketProvider._onClose (/Users/etulikov/Projects/datameta/worker/node_modules/web3-providers-ws/lib/index.js:154:27) at W3CWebSocket._dispatchEvent [as dispatchEvent] (/Users/etulikov/Projects/datameta/worker/node_modules/yaeti/lib/EventTarget.js:115:12) at W3CWebSocket.onConnectFailed (/Users/etulikov/Projects/datameta/worker/node_modules/websocket/lib/W3CWebSocket.js:219:14) at WebSocketClient. (/Users/etulikov/Projects/datameta/worker/node_modules/websocket/lib/W3CWebSocket.js:59:25) at WebSocketClient.emit (events.js:400:28) at WebSocketClient.failHandshake (/Users/etulikov/Projects/datameta/worker/node_modules/websocket/lib/WebSocketClient.js:339:10) at ClientRequest. (/Users/etulikov/Projects/datameta/worker/node_modules/websocket/lib/WebSocketClient.js:278:18) at ClientRequest.emit (events.js:400:28) at HTTPParser.parserOnIncomingClient (_http_client.js:647:27) at HTTPParser.parserOnHeadersComplete (_http_common.js:126:17) at TLSSocket.socketOnData (_http_client.js:515:22) at TLSSocket.emit (events.js:400:28) { code: 1006, reason: 'connection failed' }

And then script not work. Just send this error every 1-2 minutes

[ERR UPDATING MAIN PRICE] Error: Invalid JSON RPC response: "upstream connect error or disconnect/reset before headers. reset reason: connection failure"

etulikov commented 2 years ago

After errors logs looks like these

Screenshot 2022-06-23 at 23 38 14
Linch1 commented 2 years ago

Hello, to be honest I think that is a problem with the provider you are using, on the moralis forum someone also got the same issues but they didn't give a real solution to solver this, i left here the threads

https://forum.moralis.io/t/server-error-from-the-speedy-nodes/10575

https://forum.moralis.io/t/getpastevents-bsc-error-connection-termination/10931/4

A solution could be to have a little worker that every minute count the records inside the history_transaction model, this one ( https://github.com/Linch1/Web3TokenCharting/blob/master/server/models/history_transactions.js ) and restart the process if the count did not change

for examlpe in pseudocode:

// import mongoose and the history_transactions model
// connect to mongodb
let initalCOunt = history_transactions.count()
while( true ){

sleep( 1minute ) 
let newCount = history_transactions.count()
if( intialCount == newCOunt ) { // bot has crashed
os.execute(" pm2 restart <process_id> ")
}

}

I left here the script that i'm using to achieve this

https://gist.github.com/Linch1/74ecce7711d7afe8031c01b0b3c40865

etulikov commented 2 years ago

@Linch1 you mean I need lunch another worker which check transactions every minute and restart main worker if transactionsCount >= newTransactionsCount?

Linch1 commented 2 years ago

Yeah fastest way to avoid this issue, i think you can just use this one

https://gist.github.com/Linch1/74ecce7711d7afe8031c01b0b3c40865

just change the line 32

etulikov commented 2 years ago

Yeah fastest way to avoid this issue, i think you can just use this one

https://gist.github.com/Linch1/74ecce7711d7afe8031c01b0b3c40865

just change the line 32

Thank you very much