Browse Source

Ensure connections are closed before WaitGroup marked as done

The previous ordering of defers meant the listener's connWG could fire and wake up other goroutines before the connection closed. Unsure if this caused any real bugs but this commit should make the code more correct.
pull/13960/head
Chris S. Kim 2 years ago committed by Chris S. Kim
parent
commit
7f2732e12c
  1. 8
      connect/proxy/listener.go

8
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 {

Loading…
Cancel
Save