Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

CONNECTION ERROR: Provider started to reconnect before the response got received! #3886

Closed
snitovets opened this issue Jan 26, 2021 · 14 comments
Labels
Discussion P2 Medium severity bugs Stale Has not received enough activity

Comments

@snitovets
Copy link

I looking for workaround how to handle this error within my app. It was a surprise why websocket not store pending request to resolve after reconnection.

/app/node_modules/web3-core-helpers/lib/errors.js:63
return new Error('CONNECTION ERROR: Provider started to reconnect before the response got received!');
Error: CONNECTION ERROR: Provider started to reconnect before the response got received!
at Object.PendingRequestsOnReconnectingError (/app/node_modules/web3-core-helpers/lib/errors.js:63:16)
at /app/node_modules/web3-providers-ws/lib/index.js:332:37
at Map.forEach ()
at WebsocketProvider.reconnect (/app/node_modules/web3-providers-ws/lib/index.js:331:28)
at WebsocketProvider._onClose (/app/node_modules/web3-providers-ws/lib/index.js:149:14)
at W3CWebSocket._dispatchEvent [as dispatchEvent] (/app/node_modules/yaeti/lib/EventTarget.js:115:12)
at W3CWebSocket.onClose (/app/node_modules/websocket/lib/W3CWebSocket.js:228:10)
at WebSocketConnection. (/app/node_modules/websocket/lib/W3CWebSocket.js:201:17)
at WebSocketConnection.emit (node:events:379:20)
at WebSocketConnection.EventEmitter.emit (node:domain:470:12)
at WebSocketConnection.handleSocketClose (/app/node_modules/websocket/lib/WebSocketConnection.js:389:14)
at TLSSocket.emit (node:events:391:22)
at TLSSocket.EventEmitter.emit (node:domain:470:12)
at node:net:667:12
at TCP.done (node:_tls_wrap:573:7)

Originally posted by @snitovets in #1354 (comment)

@snitovets snitovets changed the title I looking for workaround how to handle this error within my app. It was a surprise why websocket not store pending request to resolve after reconnection. CONNECTION ERROR: Provider started to reconnect before the response got received! Jan 26, 2021
@GregTheGreek
Copy link
Contributor

From my understanding, you're hoping that web3js acts stateful and maintains a cache of the web socket events?

@snitovets
Copy link
Author

Yes. I hoped ws natively caching pending requests. Should I have to manually store pending requests while provider reconnects? And how to handle this error? provider.on('close', ...) ?

@GregTheGreek
Copy link
Contributor

Typically speaking, we try to be as stateless as possible (there's a few areas where we obviously cannot be). What i would do is perhaps keep track of the last seen block by your application and on a failure case restart using fromBlock

@spacesailor24 spacesailor24 added Discussion P2 Medium severity bugs labels Mar 5, 2021
@spacesailor24
Copy link
Contributor

Hey there, just wanted to check if Greg's recommendation satisfies your request?

@snitovets
Copy link
Author

Not really, I can't imagine how to apply such idea to my needs. This error happens if transaction sent and reconnection happens while i'm waiting for transactionReceipt event.

@joeytwiddle
Copy link

joeytwiddle commented May 1, 2021

@snitovets In case it helps you: In our organisation, we don't rely on waiting for the receipt. There are multiple reasons why we cannot rely on it:

  1. A network error such as the one you are experiencing
  2. Perhaps our API server or our geth node is restarted, while waiting for the transaction to be mined. In that case no receipt is received.
  3. If there is high congestion, we might get a timeout while waiting for the transactionReceipt. But if the gasPrice is sufficient, that transaction will usually get mined later. But by then it's too late, we won't see the receipt from it. (At the time we wrote the system, web3 would not let us configure that timeout to be longer.)
  4. Perhaps most importantly: the transaction is mined with 2 blocks confirmation, but that block is later discarded (becomes an uncle block), so this receipt is not really valid anyway!

In light of this, we don't really pay much attention to the returned receipts.

What do we do instead?

  1. We get the transaction hash from the request, before we send it:
       const transactionHash = '0x' + signedTransaction.hash().toString('hex').toLowerCase();
       // not sure if toLowerCase() is really needed or desirable
  2. We store that somewhere stateful, e.g. the DB (in case our API server crashes or is restarted).
  3. We have a loop running (even after API restart) that looks up that transactionHash on the blockchain, and waits until it is seen 20 blocks behind the head. Only then we can be confident that the transaction was mined and confirmed. Then we can get the transaction receipt object from the blockchain.

That's obviously more steps, but hopefully a bit more robust.

I would also appreciate if anyone has any criticism of our process!

@joeytwiddle
Copy link

By the way, did you ever find out why this error was occurring? I would like to compile a list of reasons and solutions in #4016.

@github-actions
Copy link

github-actions bot commented Jul 1, 2021

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 Jul 1, 2021
@srpatel19590
Copy link

srpatel19590 commented Feb 13, 2022

I'm facing the same issue.

Error: PollingBlockTracker - encountered an error while attempting to update latest block:
Error: CONNECTION ERROR: Provider started to reconnect before the response got received!

@snitovets Did you manage to fix this?

@zOthix
Copy link

zOthix commented May 13, 2022

Having the same error did any one manage to fix it?

@SalmaanChicmic
Copy link

Same error! Any Updates?

@srpatel19590
Copy link

Public and shared RPC instances are restarting WebSocket connections sometimes. Hence we get this error. Using the dedicated RPC instance solved this problem for me

@joeytwiddle
Copy link

Yes, we also had to give up on ws:// so now we only use http:// to communicate with the geth node.

@rj03hou
Copy link

rj03hou commented Feb 1, 2023

Same error! Any Updates?
close by timeout 😓

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Discussion P2 Medium severity bugs Stale Has not received enough activity
Projects
None yet
Development

No branches or pull requests

8 participants