From 96f3808dc98509a0c471d70ad1862e30a252c6a9 Mon Sep 17 00:00:00 2001 From: Jin Date: Sat, 7 Mar 2020 07:55:05 +0800 Subject: [PATCH] BUG:dynamicbanscore deadlock --- connmgr/dynamicbanscore.go | 2 +- connmgr/dynamicbanscore_test.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/connmgr/dynamicbanscore.go b/connmgr/dynamicbanscore.go index bc3c2a45..38180bac 100644 --- a/connmgr/dynamicbanscore.go +++ b/connmgr/dynamicbanscore.go @@ -71,7 +71,7 @@ type DynamicBanScore struct { func (s *DynamicBanScore) String() string { s.mtx.Lock() r := fmt.Sprintf("persistent %v + transient %v at %v = %v as of now", - s.persistent, s.transient, s.lastUnix, s.Int()) + s.persistent, s.transient, s.lastUnix, s.int(time.Now())) s.mtx.Unlock() return r } diff --git a/connmgr/dynamicbanscore_test.go b/connmgr/dynamicbanscore_test.go index 6dcd64d4..c6d67b49 100644 --- a/connmgr/dynamicbanscore_test.go +++ b/connmgr/dynamicbanscore_test.go @@ -66,3 +66,15 @@ func TestDynamicBanScoreReset(t *testing.T) { t.Errorf("Failed to reset ban score.") } } + +// TestDynamicBanScoreString +func TestDynamicBanScoreString(t *testing.T) { + var bs DynamicBanScore + base := time.Now() + + r := bs.increase(100, 50, base) + if r != 150 { + t.Errorf("Unexpected result %d after ban score increase.", r) + } + t.Log(bs.String()) +}