Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Fix race condition on Windows - #118

Merged
as-cii merged 2 commits into
masterfrom
as-fix-race-condition
Feb 3, 2017
Merged

as-cii merged 2 commits into
masterfrom
as-fix-race-condition

Conversation

@as-cii

@as-cii as-cii commented Jan 31, 2017 •

Copy link
Copy Markdown
Contributor

This pull request fixes an Access Violation exception that was occurring on Windows when closing a file handle while a WaitForMultipleObjects call was still in progress. As specified on MSDN, «if one of the handles is closed while the wait is still pending, the function's behavior is undefined». This was causing hard crashes on packages like the tree-view where a lot of I/O is performed in the tests.

This pull request fixes it by always closing the file handle after WaitForMultipleObjects returns. Now, when the user calls .unwatch(), we will mark the handle as "canceled", wake up PlatformThread, wait until it finishes waiting on all the handles (i.e. when WaitForMultipleObjects returns) and then delete the desired file handle in the main thread.

@as-cii
as-cii force-pushed the as-fix-race-condition branch 2 times, most recently from 80f3499 to 58f6630 Compare January 31, 2017 13:04
@as-cii
as-cii force-pushed the as-fix-race-condition branch 2 times, most recently from 6a6a4ea to 7fbefa7 Compare February 1, 2017 12:48
This commit fixes an Access Violation exception that was occurring on
Windows when closing a file handle while a `WaitForMultipleObjects` call
was still in progress. As specified on MSDN, "if one of the handles is
closed while the wait is still pending, the function's behavior is
undefined.". This was causing hard crashes on packages like the
tree-view where a lot of I/O is performed in the tests.

This commit fixes it by always closing the file handle after
WaitForMultipleObjects returns. Now, when the user calls `.unwatch()`,
we will mark the handle as "canceled", wake up `PlatformThread`, wait
until it finishes waiting on all the handles (i.e. when
`WaitForMultipleObjects` returns) and then delete the desired file
handle in the main thread.
@as-cii
as-cii force-pushed the as-fix-race-condition branch from 7fbefa7 to 92b07f7 Compare February 1, 2017 12:50
@maxbrunsfeld

Copy link
Copy Markdown
Contributor

Wow, nice job tracking this down.

@as-cii
as-cii merged commit cb43453 into master Feb 3, 2017
@as-cii
as-cii deleted the as-fix-race-condition branch February 3, 2017 08:58
@as-cii as-cii mentioned this pull request Mar 15, 2017
13 tasks done
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants