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
This commit is contained in:
parent
7114c8a1e9
commit
cb52f393f4
8
user.go
8
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()
|
||||
|
Loading…
Reference in New Issue
Block a user