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

Fix early pipe shutdown with Windows ProcessMonitor #3726

Merged
merged 1 commit into from
Feb 28, 2021
Merged

Fix early pipe shutdown with Windows ProcessMonitor #3726

merged 1 commit into from
Feb 28, 2021

Conversation

SeanTAllen
Copy link
Member

@SeanTAllen SeanTAllen commented Feb 28, 2021

This commit fixes a fun bug that results from multiple bits coming together.

First, the ProcessMonitor when running on Windows doesn't using ASIO. Instead
of having events pushed to it, we poll periodically to see if there's anything
to read or if we can write any pending writes.

Because of the polling, it is possible that we will attempt to read when there's
no data in the pipe. When using non-blocking IO with pipes, a read that would return
0 bytes returns an error and sets the error code to a no data error code.

We were interpreting the no data code as it should be when using blocking io. When
using non-blocking io, there error communicates "no data right now, try again later"
which wasn't what we were doing.

The same incorrect handling of the "no data" error code was present in the write code
path as well. That has also been fixed.

Fixes #3674

@SeanTAllen SeanTAllen added the changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge label Feb 28, 2021
@SeanTAllen
Copy link
Member Author

@kulibali here's the PR for testing.

@@ -172,14 +178,17 @@ class _Pipe
bytes_to_read, addressof bytes_read, USize(0))
let winerr = @GetLastError[I32]()
if not ok then
if (winerr == _ERRORBROKENPIPE()) or (winerr == _ERRORNODATA()) then
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_ERRORNODATA should be impossible to get here based on doing non blocking and us having previously peeked to know there is data to read.

@SeanTAllen SeanTAllen force-pushed the 3674 branch 5 times, most recently from 3ee2d26 to be44d0d Compare February 28, 2021 02:32
This commit fixes a fun bug that results from multiple bits coming together.

First, the ProcessMonitor when running on Windows doesn't using ASIO. Instead
of having events pushed to it, we poll periodically to see if there's anything
to read or if we can write any pending writes.

Because of the polling, it is possible that we will attempt to read when there's
no data in the pipe. When using non-blocking IO with pipes, a read that would return
0 bytes returns an error and sets the error code to a no data error code.

We were interpreting the no data code as it should be when using blocking io. When
using non-blocking io, there error communicates "no data right now, try again later"
which wasn't what we were doing.

The same incorrect handling of the no data error code is also present in the write
code for Windows and is fixed by this commit.

Fixes #3674
Copy link
Member

@chalcolith chalcolith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @SeanTAllen! I have run the corrall test suite a couple of dozen times in a row without failures. Previously they woud fail quite often.

@SeanTAllen SeanTAllen merged commit e937dc2 into main Feb 28, 2021
@SeanTAllen SeanTAllen deleted the 3674 branch February 28, 2021 04:04
github-actions bot pushed a commit that referenced this pull request Feb 28, 2021
github-actions bot pushed a commit that referenced this pull request Feb 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ProcessMonitor on Windows does not always receive all of stdout from child processes
2 participants