-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Starting many threaded processes breaks asynchronous read operations when using WaitForExit(int) #108395
Comments
cc @stephentoub |
I just hit this again with But I might have found a reason this happens. My It is basically printing 3 multiline strings to I suspect that was the same as I before, and by luck, ping on both Windows and Linux also seems to do some multiline print at the end. I have no idea what threads/threadpool pressure have to do with this. |
This comment was marked as off-topic.
This comment was marked as off-topic.
cc @tmds, @adamsitnik, for insights / improvement ideas. |
This is what That is: if you specify a timeout, it does NOT wait for the output to have been fully received. This has always been the behavior for .NET Core, and from the report it is also the behavior for .NET 4.7.2 (but perhaps not .NET 2.0/3.5). After Or, if you don't want to wait indefinitely to receive the output, it is also possible to call |
The issue has nothing to do with timeouts. The process exits normally (specifically why I used
Can this bit of info be added to docs? |
I meant: returns when called with a timeout argument. |
The docs say "To ensure that asynchronous event handling has been completed, call the WaitForExit() overload that takes no parameter after receiving a true from this overload.". It does the exact same thing as calling the method with an infinite timeout. except that it is more succinct code. |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, my bad. I guess this can be closed then. |
Description
While modernizing IronScheme tooling, I have upgraded my basic test runner from .NET 2.0/3.5 to newer frameworks.
The runner is simple, it just creates a process and run some native Scheme tests and then checks the output. For this I use asynchronous read operations.
To speed up tests, I decided to just run tests in parallel.
This is however when things started to break.
Data from
StandardOutput
andStandardError
started getting truncated.I also use the
WaitForExit
overload with a timeout (in ms) parameter. The process does not timeout however and exits normally.Further testing indicated this bug has been around since .NET 4.0 as running it on .NET 3.5 works correctly.
However when using
WaitForExit()
without any arguments (or-1
akaTimeout.Infinite
), no versions has this issue.The issue also only seems to popup reliably when using more than threads than half or more than your processor count (16 logical on my desktop, fails with 8, but fine for 6 threads, does the same on a CI box with only 1 logical processor, 2 or more in this case).
Reproduction Steps
Expected behavior
All threads should complete with expected output.
Actual behavior
Some threads has truncated output.
Regression?
Yes, works on .NET 2.0/3.5.
Tested on .NET 4.7.2, .NET 8.0 and .NET 9.0 on Windows, fails.
Tested on .NET 9.0 Linux, fails. (use
ping -c 4 1.1.1.1
and check foravg
in output)Known Workarounds
No response
Configuration
Windows 10. Ubuntu Linux. Code is run in release.
Other information
Excuse the crudity of my repro code (and also has to compile for .NET 2). Also tried to keep any other issues from intereferring.
As I dont really bother with multithreaded code, it is not really obvious what caused this regression.
This code is likely the issue.
https://github.com/dotnet/runtime/blob/main/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Windows.cs#L180
Update:
Fails under Linux too and has same 'suspect' code.
https://github.com/dotnet/runtime/blob/main/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Unix.cs#L208
The text was updated successfully, but these errors were encountered: