mirror of https://github.com/status-im/consul.git
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.
This commit is contained in:
parent
92c615c35f
commit
7f2732e12c
|
@ -166,9 +166,11 @@ func (l *Listener) Serve() error {
|
||||||
|
|
||||||
// handleConn is the internal connection handler goroutine.
|
// handleConn is the internal connection handler goroutine.
|
||||||
func (l *Listener) handleConn(src net.Conn) {
|
func (l *Listener) handleConn(src net.Conn) {
|
||||||
defer src.Close()
|
defer func() {
|
||||||
// Make sure Listener.Close waits for this conn to be cleaned up.
|
// Make sure Listener.Close waits for this conn to be cleaned up.
|
||||||
defer l.connWG.Done()
|
src.Close()
|
||||||
|
l.connWG.Done()
|
||||||
|
}()
|
||||||
|
|
||||||
dst, err := l.dialFunc()
|
dst, err := l.dialFunc()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue