Closed overfl0 closed 6 years ago
The 1006 websocket code means you got disconnected for some reason. This doesn't sound very helpful, but that's about as much information as the 1006 code gives you.
Judging by this happening on the standard gateway and not the voice one, I'm going to guess that this is a 'Connection reset by peer' error. To quote this thread:
"Connection reset by peer" is the TCP/IP equivalent of slamming the phone back on the hook.
It's more polite than merely not replying, leaving one hanging, but it's not the FIN-ACK expected of the truly polite TCP/IP converseur.
In short, for some reason, your connection was lost, and this was your network adapter's way of ensuring you weren't pointlessly listening to a dead connection. You shouldn't expect this often if you have a stable internet provider, and it's not really too much to worry about, especially because the library reconnects for you when it next can.
Thank you for your answer. I understand what is a connection reset by peer type of error, but I was saying that I would expect discord.py to catch that error and then try to reconnect and re-send the same message after establishing the connection, without raising the exception at all.
Note that my message has been lost forever now (and the whole code that was supposed to run afterwards was not run either, obviously).
Does this mean that I am expected to enclose ALL my message sending calls with try/except statements?!? This doesn't seem really reasonable.
This idea seems nice on paper but to actually do it requires a bit more effort than you think.
First, every request you send acquires a lock. This means that there's a "queue" for every type of request that is waiting on that lock. This is for rate limit handling.
Second, in order to figure out when we're connected to the internet again we have to actually do a request at specific intervals. This means that we have to sleep an indeterminate amount of time to retry the request and see if it succeeds. If it fails then we continue the loop at a higher interval (typically using exponential backoff -- similar to the rewrite connect logic).
There is already a 5-time retry for requests if they return a 502, extending the logic to deal with internet connection errors is a bit more complicated and can end up leading to the lock being indefinitely held for longer than it should be and just spamming discord with requests.
In the official client when you send a message without internet it doesn't wait until your internet is back to send the message probably for similar reasons.
Branch:
rewrite
pip freeze
yields:discord.py==1.0.0a1384
Stacktrace:
Around two minutes later, judging by the logs, I also got the following:
The message was never re-sent afterwards. Wasn't discord.py supposed to catch this exception and retry sending the message?
Note:
self
points to a class inheriting fromdiscord.Client
.