1
0
Fork 0
mirror of https://github.com/fluffle/goirc synced 2025-05-12 10:41:42 +00:00

Fix connection cleanup when context is canceled

Signed-off-by: Luca Bigliardi <shammash@google.com>
This commit is contained in:
Luca Bigliardi 2021-03-27 11:35:19 +01:00 committed by Alex Bee
parent c874d8df17
commit 58c9607dfb
2 changed files with 28 additions and 2 deletions

View file

@ -503,13 +503,17 @@ func (conn *Conn) ping(ctx context.Context) {
// It pulls Lines from the input channel and dispatches them to any
// handlers that have been registered for that IRC verb.
func (conn *Conn) runLoop(ctx context.Context) {
defer conn.wg.Done()
for {
select {
case line := <-conn.in:
conn.dispatch(line)
case <-ctx.Done():
// control channel closed, bail out
// control channel closed, trigger Cancel() to clean
// things up properly and bail out
// We can't defer this, because Close() waits for it.
conn.wg.Done()
conn.Close()
return
}
}