Skip to content

Commit

Permalink
Use sync.Once to properly support concurrent calls to Close
Browse files Browse the repository at this point in the history
Signed-off-by: Mathieu Champlon <mathieu.champlon@docker.com>
  • Loading branch information
mat007 committed Jan 13, 2025
1 parent 9d32dd6 commit 71048cd
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions pipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"net"
"os"
"runtime"
"sync"
"time"
"unsafe"

Expand Down Expand Up @@ -316,6 +317,7 @@ type win32PipeListener struct {
path string
config PipeConfig
acceptCh chan (chan acceptResponse)
closeOnce sync.Once
closeCh chan struct{}
doneCh chan struct{}
}
Expand Down Expand Up @@ -573,14 +575,10 @@ func (l *win32PipeListener) Accept() (net.Conn, error) {
}

func (l *win32PipeListener) Close() error {
select {
case <-l.doneCh:
case <-l.closeCh:
<-l.doneCh
default:
l.closeOnce.Do(func() {
close(l.closeCh)
<-l.doneCh
}
})
<-l.doneCh
return nil
}

Expand Down

0 comments on commit 71048cd

Please sign in to comment.