fleaz / CptHook

Receive webhooks from different applications and post them to IRC channels
MIT License
17 stars 8 forks source link

Improve handling of connection issues 1/ #61

Closed kmille closed 3 years ago

kmille commented 3 years ago

There was a problem in the automatic reconnect loop: If the connection to the IRC server is dropped it will not be reestablished because the call to client.Server() blocks forever. This is fixed by not calling it at this point. But there are other issues we have to tackle.

The first one is our locking. We still have a big issue here if the following happens:

https://github.com/fleaz/CptHook/blob/4d1839ae1aa619f6648c7aa03d412722d378def5/irc.go#L121-L129

If we want to rewrite the lock logic, we have to think about two scenarios:

1) How do we handle the time between irc-connection-is-down and the-library-knows-that-the-connection-is-down? The library sends continuously a PING (every 20 seconds is the smallest time interval we can use). If now() - time_last(PONG) is > 60 seconds, the connection goes in state disconnected. Then Connect() returns and we reconnect.

2) What happens if the connection to the IRC server is down, but our http server works and is used? We can