diff --git a/htlcswitch/queue.go b/htlcswitch/queue.go index 83d6eb6c..58ac10fe 100644 --- a/htlcswitch/queue.go +++ b/htlcswitch/queue.go @@ -67,8 +67,6 @@ func (p *packetQueue) Stop() { close(p.quit) p.queueCond.Signal() - - p.wg.Wait() } // packetCoordinator is a goroutine that handles the packet overflow queue. @@ -126,8 +124,8 @@ func (p *packetQueue) packetCoordinator() { p.queueCond.L.Lock() p.queue[0] = nil p.queue = p.queue[1:] - p.queueCond.L.Unlock() atomic.AddInt32(&p.queueLen, -1) + p.queueCond.L.Unlock() case <-p.quit: return } diff --git a/htlcswitch/queue_test.go b/htlcswitch/queue_test.go index a8e59ec1..ff889bff 100644 --- a/htlcswitch/queue_test.go +++ b/htlcswitch/queue_test.go @@ -29,6 +29,14 @@ func TestWaitingQueueThreadSafety(t *testing.T) { }) } + // The reported length of the queue should be the exact number of + // packets we added above. + queueLength := q.Length() + if queueLength != numPkts { + t.Fatalf("queue has wrong length: expected %v, got %v", numPkts, + queueLength) + } + var b []lnwire.MilliSatoshi for i := 0; i < numPkts; i++ { q.SignalFreeSlot() @@ -42,6 +50,14 @@ func TestWaitingQueueThreadSafety(t *testing.T) { } } + // The length of the queue should be zero at this point. + time.Sleep(time.Millisecond * 50) + queueLength = q.Length() + if queueLength != 0 { + t.Fatalf("queue has wrong length: expected %v, got %v", 0, + queueLength) + } + if !reflect.DeepEqual(b, a) { t.Fatal("wrong order of the objects") }