mirror of
https://github.com/osrg/gobgp.git
synced 2024-05-11 05:55:10 +00:00
server: fix Watcher InfiniteChannel leak
Signed-off-by: FUJITA Tomonori <[email protected]>
This commit is contained in:
+5
-11
@@ -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 {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user