diff --git a/connect/proxy/listener.go b/connect/proxy/listener.go index 546658d692..7839df0428 100644 --- a/connect/proxy/listener.go +++ b/connect/proxy/listener.go @@ -166,9 +166,11 @@ func (l *Listener) Serve() error { // handleConn is the internal connection handler goroutine. func (l *Listener) handleConn(src net.Conn) { - defer src.Close() - // Make sure Listener.Close waits for this conn to be cleaned up. - defer l.connWG.Done() + defer func() { + // Make sure Listener.Close waits for this conn to be cleaned up. + src.Close() + l.connWG.Done() + }() dst, err := l.dialFunc() if err != nil {