Fix datarace while update a channel.lastEventID #30
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.
Protect the option by wrapping into a mutex. The data race is gone.
It closes #18
Provide fix and a unit test. The test was failing if run with race detection on.
go test -timeout 30s -v -race -run ^TestMultipleTopics$
....
WARNING: DATA RACE
Write at 0x00c0000120d8 by goroutine 39:
github.com/alexandrevicenzi/go-sse.(*Channel).SendMessage()
/Users/iscander/projects/go-sse/channel.go:26 +0x8c
github.com/alexandrevicenzi/go-sse.(*Server).SendMessage()
/Users/iscander/projects/go-sse/sse.go:116 +0x21b
github.com/alexandrevicenzi/go-sse.TestMultipleTopics.func2()
/Users/iscander/projects/go-sse/sse_test.go:135 +0xce
Previous write at 0x00c0000120d8 by goroutine 38:
github.com/alexandrevicenzi/go-sse.(*Channel).SendMessage()
/Users/iscander/projects/go-sse/channel.go:26 +0x8c
github.com/alexandrevicenzi/go-sse.(*Server).SendMessage()
/Users/iscander/projects/go-sse/sse.go:116 +0x21b
github.com/alexandrevicenzi/go-sse.TestMultipleTopics.func2()
/Users/iscander/projects/go-sse/sse_test.go:135 +0xce
Goroutine 39 (running) created at:
github.com/alexandrevicenzi/go-sse.TestMultipleTopics()
/Users/iscander/projects/go-sse/sse_test.go:132 +0x735
testing.tRunner()
/usr/local/Cellar/go/1.16.3/libexec/src/testing/testing.go:1193 +0x202
Goroutine 38 (running) created at:
github.com/alexandrevicenzi/go-sse.TestMultipleTopics()
/Users/iscander/projects/go-sse/sse_test.go:132 +0x735
testing.tRunner()
/usr/local/Cellar/go/1.16.3/libexec/src/testing/testing.go:1193 +0x202
...