Closed donstephan closed 9 months ago
Issue is here: https://github.com/mochi-mqtt/server/blob/65c78534dcb5861dc8ea2163ac58ce603b6e9881/server.go#L290
go s.eventLoop()
starts and the the s.publishSysTopics()
runs right after it which could race with channels in the event loop. Would be very rare (if not impossible) to hit. If I'm reading it right, you'd somehow need a pause of 1 second between those two function executions to encounter this condition. Easiest fix is to just move the s.publishSysTopics()
into the eventLoop()
function so it runs before it listens to the tickers. Or it could just be moved above the eventLoop()
execution in the server file.
Thanks @donstephan for reporting this!
The issue is *system.Info was passed into hooks, and in the Redis hook, it directly dereferenced the live info: https://github.com/mochi-mqtt/server/blob/65c78534dcb5861dc8ea2163ac58ce603b6e9881/hooks/storage/redis/redis.go#L364.
I have provided a fix in PR #365, please verify.
Looks great. Tested the PR with the redis example and no more race. Thank you much!
@donstephan , this is incorporated into v2.4.6.
When running the redis example with the golang -race flag it outputs a data race when it initially starts up. I haven't observed this happening in a live environment but noticed it when I was doing some other debugging.
Clone the repo, start a redis server on
localhost:6379
and run:I will provide a fix when I get the time to do so.