File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments