Skip to content

Commit 5f9f6a9

Browse files
committed
Fix go-logging concurrent map read-write bug
This bug sometimes fails unit tests because logging are sometimes set up in parallel. Added a RWLock to op/go-logging/level.go's moduleLeveled struct and it RLocks in GetLevel and WLocks at SetLevel Change-Id: I78e837879fece869af9a5e573930492d439a6e82 Signed-off-by: Yacov Manevich <[email protected]>
1 parent 0cfd306 commit 5f9f6a9

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

core/util/utils_test.go

+20
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
"strings"
2222
"testing"
2323
"time"
24+
25+
"github.com/op/go-logging"
2426
)
2527

2628
func TestComputeCryptoHash(t *testing.T) {
@@ -98,3 +100,21 @@ func TestFindMissingElements(t *testing.T) {
98100
}
99101
}
100102
}
103+
104+
// This test checks go-logging is thread safe with regard to
105+
// concurrent SetLevel invocation and log invocations.
106+
// Fails without the concurrency fix (adding RWLock to level.go)
107+
// In case the go-logging will be overwritten and its concurrency fix
108+
// will be regressed, this test should fail.
109+
func TestConcurrencyNotFail(t *testing.T) {
110+
logger := logging.MustGetLogger("test")
111+
go func() {
112+
for i := 0; i < 100; i++ {
113+
logging.SetLevel(logging.Level(logging.DEBUG), "test")
114+
}
115+
}()
116+
117+
for i := 0; i < 100; i++ {
118+
logger.Info("")
119+
}
120+
}

vendor/github.com/op/go-logging/level.go

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)