File tree Expand file tree Collapse file tree 1 file changed +3
-3
lines changed Expand file tree Collapse file tree 1 file changed +3
-3
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ import (
21
21
"fmt"
22
22
"net"
23
23
"sync"
24
+ "sync/atomic"
24
25
)
25
26
26
27
// connErrPair pairs conn and error which is returned by accept on sub-listeners.
@@ -38,6 +39,7 @@ type multiListener struct {
38
39
connCh chan connErrPair
39
40
// stopCh communicates from parent to child listeners.
40
41
stopCh chan struct {}
42
+ closed atomic.Bool
41
43
}
42
44
43
45
// compile time check to ensure *multiListener implements net.Listener
@@ -150,10 +152,8 @@ func (ml *multiListener) Accept() (net.Conn, error) {
150
152
// the go-routines to exit.
151
153
func (ml * multiListener ) Close () error {
152
154
// Make sure this can be called repeatedly without explosions.
153
- select {
154
- case <- ml .stopCh :
155
+ if ! ml .closed .CompareAndSwap (false , true ) {
155
156
return fmt .Errorf ("use of closed network connection" )
156
- default :
157
157
}
158
158
159
159
// Tell all sub-listeners to stop.
You can’t perform that action at this time.
0 commit comments