jaraco / irc

Full-featured Python IRC library for Python.
MIT License
390 stars 84 forks source link

Disconnect issue #184

Open zdebel opened 3 years ago

zdebel commented 3 years ago

I can't seem to figure out how should I handle a disconnect case, my bot keeps disconnecting from time to time (either the irc network issue, or something on my end), the on_disconnect event doesn't get fired. Much obliged for a snippet.

jaraco commented 3 years ago

There are lots of conditions that can lead to disconnects (other than explicit client disconnect):

The causes for these are varied, and it can be difficult to ascertain what conditions led to a disconnect or what node initiated the disconnect.

At a basic level, it's important to (a) send periodic keep-alive messages (pings), as servers may disconnect a client they believe to be idle, and (b) respond to keep-alive messages from the server.

If you're doing both of these, the best advice I can give is to inspect the client and attempt to elicit more detail about when the disconnects happen and why. Start with: how do you know your client is disconnected? Can you tell when the disconnection happened?