From cb52f393f4f999c923ce85bd962a698ccf1db522 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Sat, 21 Mar 2020 08:29:44 +0100 Subject: [PATCH] Drop messages on closed connections This prevents this panic: panic: send on closed channel goroutine 9 [running]: git.sr.ht/~emersion/soju.(*upstreamConn).SendMessage(...) /home/simon/src/soju/upstream.go:866 git.sr.ht/~emersion/soju.(*upstreamConn).handleMessage(0xc000084b40, 0xc000144680, 0x2, 0x0) /home/simon/src/soju/upstream.go:152 +0x62b git.sr.ht/~emersion/soju.(*user).run(0xc0000b8070) /home/simon/src/soju/user.go:144 +0x53d created by git.sr.ht/~emersion/soju.(*Server).Run /home/simon/src/soju/server.go:88 +0x286 --- user.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/user.go b/user.go index d896fc3..b3c5873 100644 --- a/user.go +++ b/user.go @@ -148,11 +148,19 @@ func (u *user) run() { select { case upstreamMsg := <-u.upstreamIncoming: msg, uc := upstreamMsg.msg, upstreamMsg.uc + if uc.closed { + uc.logger.Printf("ignoring message on closed connection: %v", msg) + break + } if err := uc.handleMessage(msg); err != nil { uc.logger.Printf("failed to handle message %q: %v", msg, err) } case downstreamMsg := <-u.downstreamIncoming: msg, dc := downstreamMsg.msg, downstreamMsg.dc + if dc.isClosed() { + dc.logger.Printf("ignoring message on closed connection: %v", msg) + break + } err := dc.handleMessage(msg) if ircErr, ok := err.(ircError); ok { ircErr.Message.Prefix = dc.srv.prefix()