Closed rakete closed 2 years ago
@rakete you will remove race if you will wrap publisher.Close()
with additional callback like this:
defer func() {
publisher.Close()
}()
Despite such workaround fix race however I can't say why defer publisher.Close()
produce race and additional callback makes things ok.
I actually think this is a problem with the race detector: https://github.com/golang/go/issues/51459
I don't see any actual race issues. Feel free to open a PR if I'm missing something
I thought its my code since I store the publisher in a global var and then access it from goroutines, assuming that would be safe, and now I am having second thoughts about that assumption. But your example code for demonstrating how to use the Publisher has the same problem.
This code:
compiled with:
produces this output:
The data race is detected almost every time, but sometimes it works fine. Repeat running it a couple of times to see the problem.