-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Cannot run any command with piped stdin with Nightly toolchain #4670
Comments
Your code appears to be using |
Oh I think I didnt update the example accordingly. I am pretty sure it was failing with tokio's Command too. If thats the case its probably a std bug since tokio's is just a wrapper. I will check it again asap! |
If it fails in the same error with both the standard library and Tokio, then it's a standard library bug. If that's the case, please close this issue (but feel free to add a link to the std issue). |
I just checked my example of above, and I am correctly using Tokio's Command, not std's. The only thing I import from std is the Stdio struct, which is correct (according for example to this) That said, I tried using std's Command and it worked fine in both stable and nightly. So, looks like it only panics with tokio's Command running on nightly |
Thoughts? @ipetkov |
Hmm no idea why a nightly toolchain would cause such failures, unless something has changed in the standard library which doesn't play nicely with tokio's integration. @marc2332 do you know which specific nightly version introduced the regression? alternatively, could you also try with |
I will check at what version it stopped working and get back to you :) Regarding tokio 1.17, I was actually using that version and when the error appeared I upgraded to 1.18 (just in case), where it still threw the same error. I will try with 1.17 again anyway, just to make sure I will get back to you asap :-) |
I'm pretty sure mio was bumbed in 1.17. |
Well, now I am more confused than I was before: I tried downloading some nightly builds, and it stopped working on the one released on 2022-04-30.... or maybe not? I tried checking the versions of both 2022-04-29 and 2022-04-30 and, they both are running the same build (2022-04-28), yet the one from day 30 fails? Am I going crazy? |
We hit this when preparing the 1.62 beta release (RLS broke likely due to this issue), and it seems to be caused by rust-lang/rust#96441. We're still discussing in the Rust release team what to do with that PR.
That output is indeed quite confusing. |
Filed a regression issue in rust-lang/rust#97124. We'll revert the PR on the upcoming 1.62 beta release, and most likely on nightly as well. |
Ohhh! Here are the exact commits in case it helps :') |
Hi, I'm the one to blame here. So first a bit of background before I get to what caused this issue. Sorry if this ends up being a bit of a journey. Windows requires you to be upfront about whether or not you plan to do async reads/writes. So if doing async I/O a pipe or a file has to be opened for async access. If doing synchronous I/O it has to be opened for synchronous access. The I/O handles that are sent to a child process (stdin/out/err) must be opened for synchronous access. Doing otherwise can cause unsound behaviour in the child because they will almost certainly be performing synchronous reads or writes. However, there's nothing wrong with the standard library using async for its side of the pipe because it knows it is async. So that's what it did. The child end is synchronous and our end is asynchronous. This worked fine until we realised there was a case where our async side of the pipe is given to a child process. That is when chaining processes. We give one (synchronous) side of the pipe to one child and the other (async) side to another child. A workaround was found to ensure only synchronous pipe handles are ever passed to child processes. This appears to have worked fine and hasn't caused problems yet (assuming I haven't just jinxed it). However, turning an async pipe handle synchronous is a bit awkward so a follow up PR tried to make both ends be created synchronous in some places. Which is fine and dandy for the standard library itself but the twist is we give access to third parties via So that's the full story, as I understand it so far. |
It's unfortunate that libraries depend on the child process pipes being asynchronous ones, since that wasn't a documented promise in
For 2, we could add something like a |
If you provide an Unfortunately, I don't think it's possible to change whether Tokio wraps the standard library |
Windows: `CommandExt::async_pipes` Discussed in tokio-rs/tokio#4670 was the need for third party crates to be able to force `process::Command::spawn` to create pipes as async. This implements the suggestion for a `async_pipes` method that gives third party crates that option. # Example: ```rust use std::process::{Command, Stdio}; Command::new("cmd") .async_pipes(true) .stdin(Stdio::piped()) .stdout(Stdio::piped()) .stderr(Stdio::piped()) .spawn() .unwrap(); ```
With #4824 merged tokio will use synchronous file handles for doing I/O with child processes (read/write operations will be done using the blocking threadpool) |
Windows: `CommandExt::async_pipes` Discussed in tokio-rs/tokio#4670 was the need for third party crates to be able to force `process::Command::spawn` to create pipes as async. This implements the suggestion for a `async_pipes` method that gives third party crates that option. # Example: ```rust use std::process::{Command, Stdio}; Command::new("cmd") .async_pipes(true) .stdin(Stdio::piped()) .stdout(Stdio::piped()) .stderr(Stdio::piped()) .spawn() .unwrap(); ```
Version
tokio v1.18.2
Toolchains
Platform
Windows 11
Description
I cannot spawn any
tokio::process::Comand
with a piped stdin in the Nightly toolchain.I tried this code:
I did not expect any output because it's being spawned.
Running on the stable toolchain:
Instead, when running with the nightly toolchain, it throws this error:
If I make it inherit stdin (default behavior):
It will run just fine in the nightly toolchain:
Am I missing something maybe ? 🤔
Thanks!
The text was updated successfully, but these errors were encountered: