Thread safety fix in logging and SetLevel #105
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
#104
When a logging is called concurrently with SetLevel, a panic occurs:
fatal error: concurrent map read and map write
goroutine 20 [running]:
runtime.throw(0x5f7cc0, 0x21)
/home/yacovm/OBC/go/src/runtime/panic.go:530 +0x90 fp=0xc820038d58 sp=0xc820038d40
runtime.mapaccess2_faststr(0x551020, 0xc820078780, 0x5c9cc8, 0x4, 0x10, 0x551820)
/home/yacovm/OBC/go/src/runtime/hashmap_fast.go:307 +0x5b fp=0xc820038db8 sp=0xc820038d58
_/home/yacovm/go-logging/go-logging.(_moduleLeveled).IsEnabledFor(0xc8200981e0, 0x4, 0x5c9cc8, 0x4, 0x0)
/home/yacovm/go-logging/go-logging/level.go:110 +0x62 fp=0xc820038e18 sp=0xc820038db8
_/home/yacovm/go-logging/go-logging.(_Logger).IsEnabledFor(0xc8200788a0, 0x4, 0x0)
/home/yacovm/go-logging/go-logging/logger.go:140 +0x4d fp=0xc820038e48 sp=0xc820038e18
_/home/yacovm/go-logging/go-logging.(_Logger).log(0xc8200788a0, 0x4, 0x0, 0xc8200d9b30, 0x1, 0x1)
/home/yacovm/go-logging/go-logging/logger.go:144 +0x2f fp=0xc820038eb8 sp=0xc820038e48
_/home/yacovm/go-logging/go-logging.(_Logger).Info(0xc8200788a0, 0xc8200d9b30, 0x1, 0x1)
/home/yacovm/go-logging/go-logging/logger.go:239 +0x51 fp=0xc820038ef0 sp=0xc820038eb8
_/home/yacovm/go-logging/go-logging.TestConcurrency(0xc8200a0120)
/home/yacovm/go-logging/go-logging/logger_test.go:73 +0x11f fp=0xc820038f68 sp=0xc820038ef0
testing.tRunner(0xc8200a0120, 0x6b8468)
I added a RWLock to protect the map and added a regression test that many times
fails without the locks