Skip to content

Commit

Permalink
device: receive: drain decryption queue before exiting RoutineDecryption
Browse files Browse the repository at this point in the history
It's possible for RoutineSequentialReceiver to try to lock an elem after
RoutineDecryption has exited. Before this meant we didn't then unlock
the elem, so the whole program deadlocked.

As well, it looks like the flush code (which is now potentially
unnecessary?) wasn't properly dropping the buffers for the
not-already-dropped case.

Signed-off-by: Jason A. Donenfeld <[email protected]>
  • Loading branch information
zx2c4 committed Jan 7, 2021
1 parent 85b4950 commit 29b0477
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 4 additions & 1 deletion device/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,10 @@ func (device *Device) FlushPacketQueues() {
select {
case elem, ok := <-device.queue.decryption:
if ok {
elem.Drop()
if !elem.IsDropped() {
elem.Drop()
device.PutMessageBuffer(elem.buffer)
}
}
case <-device.queue.handshake:
default:
Expand Down
15 changes: 14 additions & 1 deletion device/receive.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,20 @@ func (device *Device) RoutineDecryption() {
for {
select {
case <-device.signals.stop:
return
for {
select {
case elem, ok := <-device.queue.decryption:
if ok {
if !elem.IsDropped() {
elem.Drop()
device.PutMessageBuffer(elem.buffer)
}
elem.Unlock()
}
default:
return
}
}

case elem, ok := <-device.queue.decryption:

Expand Down

0 comments on commit 29b0477

Please sign in to comment.