server: fix Watcher InfiniteChannel leak

Signed-off-by: FUJITA Tomonori <[email protected]>
This commit is contained in:
FUJITA Tomonori
2016-11-24 14:09:53 +09:00
parent 38c47609a2
commit daca3cf3bc
2 changed files with 10 additions and 11 deletions
+5 -11
View File
@@ -2554,17 +2554,11 @@ func (w *Watcher) Stop() {
}
}
w.ch.Close()
// make sure the loop function finishes
func() {
for {
select {
case <-w.realCh:
default:
return
}
}
}()
cleanInfiniteChannel(w.ch)
// the loop function goroutine might be blocked for
// writing to realCh. make sure it finishes.
for range w.realCh {
}
}
}
+5
View File
@@ -138,4 +138,9 @@ func TestMonitor(test *testing.T) {
assert.Equal(b.PathList[0].GetNlri().String(), "10.0.0.0/24")
assert.Equal(b.PathList[0].IsWithdraw, true)
if _, err := t.AddPath("", []*table.Path{table.NewPath(nil, bgp.NewIPAddrPrefix(24, "10.0.0.0"), true, attrs, time.Now(), false)}); err != nil {
log.Fatal(err)
}
//stop the watcher still having an item.
w.Stop()
}