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

rust-script can leave orphaned child processes when killed on Windows #24

Open
alebastr opened this issue Jun 16, 2021 · 2 comments
Open
Labels
bug Something isn't working

Comments

@alebastr
Copy link

If you kill the rust-script process it will not pass the kill signal to the child process with a compiled binary. With the way I use rust-script, this leaves me with a few stale processes that I have to clean up manually.

It's easy to address this for unix (although that'll likely disrupt deferred cache cleanup)

Example diff
diff --git a/src/main.rs b/src/main.rs
index 6ea81a3..c97b3fc 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -27,6 +27,7 @@ use serde::{Deserialize, Serialize};
 use std::ffi::OsString;
 use std::fs;
 use std::io::{Read, Write};
+use std::os::unix::process::CommandExt;
 use std::path::{Path, PathBuf};
 use std::process::Command;

@@ -481,18 +482,17 @@ fn try_main() -> MainResult<i32> {
         })
     };

-    let exit_code = if action.execute {
+    if action.execute {
         let cmd_name = action.build_kind.exec_command();
         info!("running `cargo {}`", cmd_name);
         let run_quietly = !action.cargo_output;
         let mut cmd = action.cargo(cmd_name, &args.script_args, run_quietly)?;

-        cmd.status().map(|st| st.code().unwrap_or(1))?
+        let err = cmd.exec();
+        Err(MainError::from(err))
     } else {
-        0
-    };
-
-    Ok(exit_code)
+        Ok(0)
+    }
 }

 /**

and not so much for Windows: see implementation used by cargo run or wexecvp-based implementation suggested for exec crate.

@fornwall fornwall added the bug Something isn't working label Jul 10, 2021
@fornwall
Copy link
Owner

@alebastr Thanks for the nice description. Looking into this.

fornwall added a commit that referenced this issue Apr 27, 2022
@fornwall
Copy link
Owner

For reference: we transitioned to unix exec in 445d9cf last year - leaving this open for the Windows part (contributions are welcome, as I don't know much Windows myself).

@fornwall fornwall changed the title rust-script can leave orphaned child processes when killed rust-script can leave orphaned child processes when killed on Windows Mar 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants