Skip to content

Commit

Permalink
Hold lock while writing to b.notify
Browse files Browse the repository at this point in the history
  • Loading branch information
edaniels committed Jul 22, 2024
1 parent e139c8a commit d55a60c
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions packetio/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,13 @@ func (b *Buffer) Write(packet []byte) (int, error) {
waiting := b.waiting
b.waiting = false

b.mutex.Unlock()

if waiting {
select {
case b.notify <- struct{}{}:
default:
}
}
b.mutex.Unlock()

return len(packet), nil
}
Expand Down Expand Up @@ -280,16 +279,11 @@ func (b *Buffer) Close() (err error) {
return nil
}

waiting := b.waiting
b.waiting = false
b.closed = true

close(b.notify)
b.mutex.Unlock()

if waiting {
close(b.notify)
}

return nil
}

Expand Down

0 comments on commit d55a60c

Please sign in to comment.