Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions net/multi_listen.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"net"
"sync"
"sync/atomic"
)

// connErrPair pairs conn and error which is returned by accept on sub-listeners.
Expand All @@ -38,6 +39,7 @@ type multiListener struct {
connCh chan connErrPair
// stopCh communicates from parent to child listeners.
stopCh chan struct{}
closed atomic.Bool
}

// compile time check to ensure *multiListener implements net.Listener
Expand Down Expand Up @@ -150,10 +152,8 @@ func (ml *multiListener) Accept() (net.Conn, error) {
// the go-routines to exit.
func (ml *multiListener) Close() error {
// Make sure this can be called repeatedly without explosions.
select {
case <-ml.stopCh:
if !ml.closed.CompareAndSwap(false, true) {
return fmt.Errorf("use of closed network connection")
default:
}

// Tell all sub-listeners to stop.
Expand Down