sm00th / bitlbee-discord

Bitlbee plugin for Discord (http://discordapp.com)
GNU General Public License v2.0
290 stars 27 forks source link

Heartbeat and reconnect opcodes #115

Closed arcnmx closed 6 years ago

arcnmx commented 6 years ago

Occasionally the gateway will request a heartbeat, and the client must respond otherwise you'll be logged out and get OPCODE_INVALID_SESSION, requiring a reconnect to get everything working again (in this state you appear offline and receive no messages, but are still able to send outgoing messages). It's pretty common and happens to me multiple times per day when DMing with friends. Possibly related to #95?

This PR triggers a reconnect when requested, and also handles the heartbeat request so it doesn't happen in the first place!

sm00th commented 6 years ago

Thanks, looks good. I think this might also solve #71. I think OPCODE_RECONNECT should use imcb_log, not imcb_error as it is hardly an error. Originally I wanted to make reconnect on this opcode invisible to user, but at this point this solution is just as good.

How tested is it on your side? I think I'd run it for a couple of days before merging.

arcnmx commented 6 years ago

I've only been running it for 24 hours at this point - I got fed up yesterday morning that I couldn't message anyone for 5 to 20 minutes without getting silently disconnected. Noticed warnings in the log about unhandled heartbeat, closely followed by unhandled invalid session. After applying the fix I have not run into that issue again so far.

I still get Error: Failed to read data occasionally so that seems like an unrelated problem.

arcnmx commented 6 years ago

This is likely also related to #75

sm00th commented 6 years ago

Didn't notice anything bad while running this and the code looks good. Thanks again, great work. Now we'll need to see if it helps fix #75 and #95.