Skip to content

Commit 29b0477

Browse files
committed
device: receive: drain decryption queue before exiting RoutineDecryption
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]>
1 parent 85b4950 commit 29b0477

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

device/device.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,10 @@ func (device *Device) FlushPacketQueues() {
371371
select {
372372
case elem, ok := <-device.queue.decryption:
373373
if ok {
374-
elem.Drop()
374+
if !elem.IsDropped() {
375+
elem.Drop()
376+
device.PutMessageBuffer(elem.buffer)
377+
}
375378
}
376379
case <-device.queue.handshake:
377380
default:

device/receive.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,20 @@ func (device *Device) RoutineDecryption() {
251251
for {
252252
select {
253253
case <-device.signals.stop:
254-
return
254+
for {
255+
select {
256+
case elem, ok := <-device.queue.decryption:
257+
if ok {
258+
if !elem.IsDropped() {
259+
elem.Drop()
260+
device.PutMessageBuffer(elem.buffer)
261+
}
262+
elem.Unlock()
263+
}
264+
default:
265+
return
266+
}
267+
}
255268

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

0 commit comments

Comments
 (0)