-
Notifications
You must be signed in to change notification settings - Fork 5k
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
WebSocket reconnect doesn't throw error on maxAttempts #3492
Comments
@angel200sdnot Thanks for reporting. Will investigate We have a some tests that seem to cover the case you describe but we need to look at the interaction with |
@angel200sdnot Have opened #3494 to address this. If you have a chance, could you look at the tests added there and see if they model your expectations? In the issue description you say:
At present, an error is emitted for the provider when max attempts is reached. You can listen for it by attaching a handler on the provider as shown here: #3494 makes sure subsequent requests error with Does that seem correct? |
@cgewecke This is what i currently have in place for reconnecting using async function getTransactionReceipt(transactionHash: string): Promise<any> {
try {
const result = await this.web3.eth.getTransactionReceipt(transactionHash);
return result;
} catch (err) {
if (err && err.message === 'connection not open') {
this.connectWeb3();
return this.web3.eth.getTransactionReceipt(transactionHash);
}
throw err;
}
} With {
reconnect: {
auto: true,
maxAttempts: 1,
delay: 0
}
}
In my opinion this doesn't seem correct because in that case i would need to keep handling the error and reconnecting manually. Perhaps i am looking at this the wrong way and i should be handling this differently, do you have any suggestions regarding my approach? |
I tested my code by disconnecting my internet for a couple of minutes and then reconnecting and If that was unrelated to reconnecting then this issue can be closed with #3494 |
@angel200sdnot Ah, the idea of max attempts is that it's like running your initial code in a loop, where max attempts is the upper bound. There is a bug...I think #3494 will resolve this though. Thanks so much. |
Expected behavior
An error should be thrown when the max attempts is reached while reconnecting. Next time a method gets called that requires this connection then it should try to reconnect again.
Actual behavior
WebSocket continues to try to reconnect until it succeeds. This only happens after the initial connection is successful. When the initial connection fails then the reconnection works as expected
Steps to reproduce the behavior
I noticed that this also happens even when
auto
is set to false. I was expecting to get the following error instead:Error: CONNECTION TIMEOUT: timeout of 5000 ms achived
Versions
Node: v12.16.2
Web3.js: 1.2.7
OS: Ubuntu 18.04.4 LTS
The text was updated successfully, but these errors were encountered: