Skip to content
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

Race condition in trio.hazmat.WaitForSingleObject #1271

Open
njsmith opened this issue Oct 27, 2019 · 1 comment
Open

Race condition in trio.hazmat.WaitForSingleObject #1271

njsmith opened this issue Oct 27, 2019 · 1 comment

Comments

@njsmith
Copy link
Member

njsmith commented Oct 27, 2019

https://github.com/python-trio/trio/pull/575/files#diff-ed34813c30595dc83bb2a66e0973e22dR54

This appears to have a race condition. The new thread might start waiting only after the handle has been closed. This could be fixed by making the thread close the cancel_handle.

Originally posted by @GSPP in #233 (comment)

@njsmith
Copy link
Member Author

njsmith commented Oct 27, 2019

Hmm, I think you're right. Probably difficult to hit, but not impossible.

I don't think the simple fix is quite right either though – if we move the CloseHandle into the thread, then we introduce the possibility that the handle will already be closed before we try to SetEvent in the finally block.

I guess we could use some kind of reference counting scheme, where whichever of the child thread/main thread exits last is the one who calls CloseHandle?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants