New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possible race condition between Fini and PollEvent #460
Comments
Fair point. What I'll do is move the clearing of that to after waiting for the waitgroup. |
PollEvent does not read from the stopQ in the tscreen implementation. It would be an error to call PollEvent when the application is not started. I will change Fini not to clear it, but I do need to set it during start(). |
(For anyone watching ... its pretty unlikely that you'll ever actually hit this as a real world bug.) |
My bad, I confused myself! Thanks for the quick response. |
Both
cScreen
andtScreen
will eventually set theirstopQ
channels tonil
in response toFini
. This update of the struct field is protected by a mutex, however the read of the field inPollEvent
is not, which triggers a data race.While the documentation for
PollEvent
does indicate it should be called from the main loop, it isn't clear about who is allowed to callFini
. However from the locks, it appears thatFini
is intended to be callable from anywhere, thus making the underlying data shared rather than exclusive to the main loop.As such the data access should be protected in
PollEvent
as well, even ifPollEvent
is only allowed to be called from a specific routine. Alternatively,Fini
should be documented to only be callable from the main goroutine as well (this is an API break, however)The text was updated successfully, but these errors were encountered: