commit 18f699a

delthas  ·  2025-03-11 00:34:55 +0000 UTC
parent a5fc18b
Fix retrying connection after App exits

Thanks to Antonio Mika <me@antoniomika.me> for helping me find
this issue.

This leaves a possible theoretical race condition, but should not
really happen in practice and can only be properly fixed by
refactoring existing code to use contexts.
1 files changed,  +7, -0
M app.go
M app.go
+7, -0
 1@@ -391,6 +391,9 @@ func (app *App) ircLoop(netID string) {
 2 	var delay time.Duration = 0
 3 	for app.wantsNetwork(netID) {
 4 		time.Sleep(delay)
 5+		if !app.wantsNetwork(netID) {
 6+			break
 7+		}
 8 		if delay < throttleMax {
 9 			delay += throttleInterval
10 		}
11@@ -398,6 +401,10 @@ func (app *App) ircLoop(netID string) {
12 		if conn == nil {
13 			continue
14 		}
15+		if !app.wantsNetwork(netID) {
16+			conn.Close()
17+			break
18+		}
19 		delay = throttleInterval
20 
21 		in, out := irc.ChanInOut(conn)