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
missing heartbeat handling? #12
Comments
the error 1000 is an error generated by cloudflare. the bot is still sending keepalives, but if the server side (discord) sends no traffic for 2 intervals cloudflare disconnects the socket with an error 1000. the SSL error afterwards is just D++ forced disconnect and resume by invalidating the file descriptor. in real production use, where the guilds have real traffic, this doesn't happen ( add your invite to a busier server and you'll see). I don't know how to prevent this as, as ive said heartbeat is being sent (stick some debug in there to find out) and it doesn't disrupt production use. I'll have a think about what I can do to force the connection to stay open, perhaps by low level websocket pings. |
It seems sending a low level websocket ping will prevent this (note this is not a discord API keepalive and exists in the level below): I'll test this later and also look into the hibernation issue, however I don't run my code on anything that hibernates (only on real servers) this can mess with timers and cause issues. I'll let you know what I find out. |
Well the trace level logging seems to include the heartbeat ACKs send by the server Thanks for checking it out in any case :-) |
Oh and it is not the hibernation that worries me. Disconnecting my ethernet for a minute has the same effect - and network outages do in fact happen so it would be nice for the bot to handle them correctly ^^ |
no they're sent on a timer, actually 75% of the recommended frequency so if discord says 40 seconds D++ will send them every 30 seconds. I need to add functionality to ping the underlying websocket, websocket opcode 0x09 to expect a response of type 0x0A. Simply having activity at the application layer above (discord JSON) is not enough to satisfy cloudflare. this is why you don't see it on other libraries as I've implemented websockets from scratch. |
…9) every 30 seconds and expect a PONG (0xa). If we don't, on an inactive shard we will get disconnected with opcode 8 close code 1000. Also adjust SSL code to ensure that the PING is immediately sent and doesnt wait till we have discord application level stuff to send
This is now fixed in 1.0.1 dev branch, commit 6cf1d27. |
The commit seems to fix the issue for me. Heartbeats Thanks :-) |
Describe the bug
Instead of sending a heartbeat to the discord servers every ~40 seconds the connection is shutdown with code 1000 every minute (and immediately reconnected). After the connection is closed unexpectedly (eg. TCP error) the disconnect seems to be unhandled.
To Reproduce
I noticed the disconnect issue after I suspended my computer. After wakeup the bot was naturally disconnected from discord servers but the library never noticed or fixed this. All logs (even trace) stay empty.
Expected behavior
System Details:
The text was updated successfully, but these errors were encountered: