From 07502541e473155874fe3e525e8d26a814ec3163 Mon Sep 17 00:00:00 2001 From: Conrad Hoffmann Date: Thu, 27 Jun 2024 21:31:59 +0200 Subject: [PATCH] conn: fix goroutine leak As is, soju leaks goroutines on client disconnects, because the closure started as goroutine in newConn never finishes. It gets stuck in the for loop annotated as "draining the outgoing channel", because the outgoing channel is in fact never closed. This commit fixes the issue by calling conn.Close rather than conn.conn.Close, which closes not only the underlying net.Conn (in c.conn), but also the channel. --- conn.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conn.go b/conn.go index 57cc23f..7e07a47 100644 --- a/conn.go +++ b/conn.go @@ -157,7 +157,7 @@ func newConn(srv *Server, ic ircConn, options *connOptions) *conn { break } } - if err := c.conn.Close(); err != nil && !errors.Is(err, net.ErrClosed) { + if err := c.Close(); err != nil && !errors.Is(err, net.ErrClosed) { c.logger.Printf("failed to close connection: %v", err) } else { c.logger.Debugf("connection closed")