From 51e915a8068bd893ba2ee7ba7d2e3a774bd5b4b2 Mon Sep 17 00:00:00 2001 From: fanpei91 Date: Sun, 27 Jan 2019 16:54:10 +0800 Subject: [PATCH] check length when call announcements.put --- dht.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dht.go b/dht.go index cd5f849..ab0be77 100644 --- a/dht.go +++ b/dht.go @@ -51,8 +51,13 @@ func (a *announcements) get() *announcement { func (a *announcements) put(ac *announcement) { a.mu.Lock() + defer a.mu.Unlock() + + if a.ll.Len() >= a.limit { + return + } + a.ll.PushBack(ac) - a.mu.Unlock() select { case a.input <- struct{}{}: