Skip to content

Commit

Permalink
Merge pull request #30 from denis-tingaikin/fix-race-cond
Browse files Browse the repository at this point in the history
Fix race cond
  • Loading branch information
edwarnicke authored May 27, 2024
2 parents cd38d28 + 2849d6b commit 2516196
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions connwrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type connWrap struct {
sendFDs []int
errChs []chan error
sendExecutor serialize.Executor
closed bool

recvFDChans map[inodeKey][]chan uintptr
recvedFDs map[inodeKey]uintptr
Expand Down Expand Up @@ -127,6 +128,7 @@ func (w *connWrap) close() error {
w.sendFDs = nil
w.errChs = nil
})
w.closed = true
})
return err
}
Expand Down Expand Up @@ -181,6 +183,10 @@ func (w *connWrap) SendFD(fd uintptr) <-chan error {
return errCh
}
w.sendExecutor.AsyncExec(func() {
if w.closed {
close(errCh)
return
}
w.sendFDs = append(w.sendFDs, int(fd))
w.errChs = append(w.errChs, errCh)
})
Expand Down Expand Up @@ -232,6 +238,10 @@ func (w *connWrap) String() string {
func (w *connWrap) RecvFD(dev, ino uint64) <-chan uintptr {
fdCh := make(chan uintptr, 1)
w.recvExecutor.AsyncExec(func() {
if w.closed {
close(fdCh)
return
}
key := inodeKey{
dev: dev,
ino: ino,
Expand Down

0 comments on commit 2516196

Please sign in to comment.