hub
hub copied to clipboard
Fix panic on closed channel
Fix panic in subscribers
When hub publishes messages, it first finds all matching subscribers and then calls sub.Set(m)
on them:
// Publish will send an event to all the subscribers matching the event name.
func (h *Hub) Publish(m Message) {
for k, v := range h.fields {
m.Fields[k] = v
}
for _, sub := range h.matcher.Lookup(m.Topic()) {
sub.Set(m)
}
}
However, if Unsubscribe
is called after the filtering but before the Set
, the subscriber's underlying channel is closed and Set
tries to write into a closed channel.
This PR adds channels and goroutines responsible for closing the channel.
Hey, Nice catch! Thanks for the work on this Pull Request. I think I added this bug on PR #12 🙈
I fixed the CI process, now it should work.
The modifications are approved. Thanks for the work here!
I just fixed (I think) the GitHub actions to work on forks. Can you rebase or merge with the main
branch?
I had to add an RWMutex to stop go test
from getting angry at the data race. Codecov reports a decrease in code coverage, but everything in subscriber.go
should be covered (at least GoLand says so). I think this happens because to get a 100% coverage you need to run the tests many times
About the codecov, you are right, We will ignore the patch. Fix the last comment and we are ready to merge
Codecov Report
Merging #13 into main will decrease coverage by
0.59%
. The diff coverage is77.77%
.
@@ Coverage Diff @@
## main #13 +/- ##
==========================================
- Coverage 87.09% 86.50% -0.60%
==========================================
Files 4 4
Lines 310 326 +16
==========================================
+ Hits 270 282 +12
- Misses 30 33 +3
- Partials 10 11 +1
Flag | Coverage Δ | |
---|---|---|
#unittests | 86.50% <77.77%> (-0.60%) |
:arrow_down: |
Flags with carried forward coverage won't be shown. Click here to find out more.
Impacted Files | Coverage Δ | |
---|---|---|
subscriber.go | 89.47% <77.77%> (-10.53%) |
:arrow_down: |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact)
,ø = not affected
,? = missing data
Powered by Codecov. Last update 99dcacb...de0df9d. Read the comment docs.