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
tokio::process::Command::spawn can fail with WouldBlock #2841
Comments
By the way, if this is confirmed to be an unwanted behavior, I'm interested in working on a patch. |
Hi @Yoric thanks for the report! Can't think of what would raise a Could you try to reproduce this while running under |
I'll try and do that. |
@Yoric if you're interested in checking out the tokio source and annotating the code with extra debug statements or context of where the error comes out from that might also help narrow down the cause |
Here's a minimal test. It runs // Attempt to stress tokio::process::Command::spawn
// to reproduce a `WouldBlock` error.
#[test]
fn main() {
env_logger::init();
tokio_test::block_on(async {
// A little time to launch dtruss.
// The error shows up even without this wait.
tokio::time::delay_for(std::time::Duration::new(3, 0))
.await;
let mut cmd = tokio::process::Command::new("ls");
cmd.kill_on_drop(true) // Make sure we always cleanup
.stdout(std::process::Stdio::piped());
for i in 0..10000 {
eprintln!("Process {}", i);
cmd.spawn()
.expect("Could not spawn process")
.kill()
.expect("Could not kill process");
}
});
} If fails around 2400 processes launched (and killed). As far as I can tell from
Attaching |
I fear that any solution would require a rewrite of By the way, shouldn't |
Actually, I think the reason is simple: the Unix implementation of I'm not entirely sure how we can wait for |
Thanks for pulling some logs @Yoric, I'll take a look at them. Actually I also came across this comment which points towards The master branch has a change which makes |
Yes, that's also my assumption. I have added a So, the question is which behavior is desirable:
|
We should definitely update the documentation to mention that a As for waiting until the spawn succeeds I'm not sure what we can do to be woken up when the process space clears out. It is entirely possible that the system has too many other processes running even beyond tokio's control. Happy to explore any suggestions if anyone has them! But until then I think the best course of action is to surface the error to the caller and allow them to retry if necessary... |
The documentation around returning |
Version
Platform
Description
While stress-testing a process library I'm writing, I encountered somewhat reproducible instances of
failing with a
WouldBlock
error.I expected that the underlying error would simply cause a future to be blocked, rather than returning a
Result::Err
.The text was updated successfully, but these errors were encountered: