summaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-11-24 14:09:53 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-11-24 14:09:53 +0900
commitdaca3cf3bcb855bab6f138e39fd78d2ee2bf9b22 (patch)
tree761043ee094bca1f775e9b85a32447321e3b6b95 /server
parent38c47609a2eeae67c2c9cc042adea60484c2f481 (diff)
server: fix Watcher InfiniteChannel leak
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'server')
-rw-r--r--server/server.go16
-rw-r--r--server/server_test.go5
2 files changed, 10 insertions, 11 deletions
diff --git a/server/server.go b/server/server.go
index fd0ebf1f..d83a4001 100644
--- a/server/server.go
+++ b/server/server.go
@@ -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 {
+ }
}
}
diff --git a/server/server_test.go b/server/server_test.go
index 46ef4be3..c9f142f1 100644
--- a/server/server_test.go
+++ b/server/server_test.go
@@ -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()
}