-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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 connection issue #1487
Comments
So, do you think reconnection can be done at this lib's level ? ie. try to reconnect, and raise an error only if reconnecting failed twice in a row maybe ? |
Yeah that would work, maybe even with a parameter to control the number of retries. |
For those who find this issue looking for a solution: we basically decorated our functions using web3py with tenacity. Not the best solution but unblocks the situation meanwhile core devs suggest an implementation that we can contribute. |
I ran into this yesterday when I was sent a malformed request via websocket, sometimes the websocket will just close. @Wozacosta or @jpic, are you seeing the exact same request go through after you reconnect? Or is the request somehow changing after reconnection? |
@kclowes Can you give an example of a malformed request? |
For example, if I attach to a local geth node with wscat and send a request like: |
@kclowes What you're describing seems like a different issue from the one described in the title of this issue. My guess is that you got this error because you provided a malformed JSON to geth and geth failed to deserialize it giving
Yeah, the case you've described is not possible using web3py and incase web3py is failing to sanitize user input that is causing such errors, then those need to be handled separately. Till the actual cause for the error is known, it's hard to say what would be the right fix. @kclowes Btw, there's already some code that creates a new connection when the previous connection raises an error for some reason. Might be worth checking if that actually works. web3.py/web3/providers/websocket.py Lines 55 to 60 in 0aa00c8
|
I know. It was a bad example. I can't remember the exact request I made where I saw the error. I was also using wscat rather than web3, which of course makes a difference. I was just surprised that a connection would just drop when it encountered certain errors, but not others. What I was getting at was trying to narrow down whether this was a problem with a request that led to the provider closing the websocket or a problem with the provider. In checking out the function you linked to @voith , I was able to reproduce something close to the error above by connecting to geth, issuing a request and then disconnecting from geth and issuing another request. Assuming that's representative of the original issue raised, I don't think this is a web3 problem per se, but I can see where it would be useful to retry a websocket request that comes back with a I'd also be curious to see your decorator functions @jpic, if possible, to see how you are getting around these errors. |
stale / |
Version: 5.2.2
Python: 3.6.8
OS: linux
Blockchain : Kaleido
What was wrong?
When interacting with contracts via a websocket provider, after a couple of successful requests, we get this error :
The connection drops during the interaction as
web3.isConnected()
returns true before that interaction.The text was updated successfully, but these errors were encountered: