Skip to content

Commit 71048cd

Browse files
committed
Use sync.Once to properly support concurrent calls to Close
Signed-off-by: Mathieu Champlon <[email protected]>
1 parent 9d32dd6 commit 71048cd

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

pipe.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"net"
1212
"os"
1313
"runtime"
14+
"sync"
1415
"time"
1516
"unsafe"
1617

@@ -316,6 +317,7 @@ type win32PipeListener struct {
316317
path string
317318
config PipeConfig
318319
acceptCh chan (chan acceptResponse)
320+
closeOnce sync.Once
319321
closeCh chan struct{}
320322
doneCh chan struct{}
321323
}
@@ -573,14 +575,10 @@ func (l *win32PipeListener) Accept() (net.Conn, error) {
573575
}
574576

575577
func (l *win32PipeListener) Close() error {
576-
select {
577-
case <-l.doneCh:
578-
case <-l.closeCh:
579-
<-l.doneCh
580-
default:
578+
l.closeOnce.Do(func() {
581579
close(l.closeCh)
582-
<-l.doneCh
583-
}
580+
})
581+
<-l.doneCh
584582
return nil
585583
}
586584

0 commit comments

Comments
 (0)