Skip to content

Commit 227cc3a

Browse files
committed
routing: fix missionControlStore blocks on shutting down
1 parent e3cc4d7 commit 227cc3a

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

routing/missioncontrol_store.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ type missionControlStore struct {
5050
wg sync.WaitGroup
5151
db missionControlDB
5252

53+
// TODO(yy): Remove the usage of sync.Cond - we are better off using
54+
// channes than a Cond as suggested in the official godoc.
55+
//
5356
// queueCond is signalled when items are put into the queue.
5457
queueCond *sync.Cond
5558

@@ -347,15 +350,23 @@ func (b *missionControlStore) run() {
347350
// Wait for the queue to not be empty.
348351
b.queueCond.L.Lock()
349352
for b.queue.Front() == nil {
350-
b.queueCond.Wait()
351-
353+
// To make sure we can properly stop, we must
354+
// read the `done` channel first before
355+
// attempting to call `Wait()`. This is due to
356+
// the fact when `Signal` is called before the
357+
// `Wait` call, the `Wait` call will block
358+
// indefinitely.
359+
//
360+
// TODO(yy): replace this with channels.
352361
select {
353362
case <-b.done:
354363
b.queueCond.L.Unlock()
355364

356365
return
357366
default:
358367
}
368+
369+
b.queueCond.Wait()
359370
}
360371
b.queueCond.L.Unlock()
361372

0 commit comments

Comments
 (0)