1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-18 05:14:21 -05:00

fix(task): kill descendants when killing task process on Windows (#27163)

This commit is contained in:
David Sherret 2024-12-04 12:19:06 -05:00 committed by GitHub
parent f863a623c9
commit f0586238fc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 142 additions and 37 deletions

85
Cargo.lock generated
View file

@ -1677,7 +1677,7 @@ dependencies = [
"serde", "serde",
"thiserror 1.0.64", "thiserror 1.0.64",
"winapi", "winapi",
"windows-sys 0.52.0", "windows-sys 0.59.0",
] ]
[[package]] [[package]]
@ -1767,7 +1767,7 @@ dependencies = [
"tokio", "tokio",
"uuid", "uuid",
"winapi", "winapi",
"windows-sys 0.52.0", "windows-sys 0.59.0",
] ]
[[package]] [[package]]
@ -1855,7 +1855,7 @@ dependencies = [
"log", "log",
"napi_sym", "napi_sym",
"thiserror 1.0.64", "thiserror 1.0.64",
"windows-sys 0.52.0", "windows-sys 0.59.0",
] ]
[[package]] [[package]]
@ -1974,7 +1974,7 @@ dependencies = [
"url", "url",
"webpki-root-certs", "webpki-root-certs",
"winapi", "winapi",
"windows-sys 0.52.0", "windows-sys 0.59.0",
"x25519-dalek", "x25519-dalek",
"x509-parser", "x509-parser",
"yoke", "yoke",
@ -2174,7 +2174,7 @@ dependencies = [
"uuid", "uuid",
"which 4.4.2", "which 4.4.2",
"winapi", "winapi",
"windows-sys 0.52.0", "windows-sys 0.59.0",
] ]
[[package]] [[package]]
@ -2193,9 +2193,9 @@ dependencies = [
[[package]] [[package]]
name = "deno_task_shell" name = "deno_task_shell"
version = "0.20.1" version = "0.20.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "01e09966ce29f8d26b652a43355397e1df43b85759e7824196bf0ceaeaa9a2f4" checksum = "fa3763bc068e17b6d488fb73ecda463c13ef792b0a5288b6018bc2119becd635"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"futures", "futures",
@ -2206,6 +2206,7 @@ dependencies = [
"path-dedot", "path-dedot",
"thiserror 1.0.64", "thiserror 1.0.64",
"tokio", "tokio",
"windows-sys 0.59.0",
] ]
[[package]] [[package]]
@ -4558,7 +4559,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"windows-targets 0.52.4", "windows-targets 0.48.5",
] ]
[[package]] [[package]]
@ -8623,7 +8624,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be" checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be"
dependencies = [ dependencies = [
"windows-core", "windows-core",
"windows-targets 0.52.4", "windows-targets 0.52.6",
] ]
[[package]] [[package]]
@ -8632,7 +8633,7 @@ version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9"
dependencies = [ dependencies = [
"windows-targets 0.52.4", "windows-targets 0.52.6",
] ]
[[package]] [[package]]
@ -8650,7 +8651,16 @@ version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
dependencies = [ dependencies = [
"windows-targets 0.52.4", "windows-targets 0.52.6",
]
[[package]]
name = "windows-sys"
version = "0.59.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
dependencies = [
"windows-targets 0.52.6",
] ]
[[package]] [[package]]
@ -8670,17 +8680,18 @@ dependencies = [
[[package]] [[package]]
name = "windows-targets" name = "windows-targets"
version = "0.52.4" version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
dependencies = [ dependencies = [
"windows_aarch64_gnullvm 0.52.4", "windows_aarch64_gnullvm 0.52.6",
"windows_aarch64_msvc 0.52.4", "windows_aarch64_msvc 0.52.6",
"windows_i686_gnu 0.52.4", "windows_i686_gnu 0.52.6",
"windows_i686_msvc 0.52.4", "windows_i686_gnullvm",
"windows_x86_64_gnu 0.52.4", "windows_i686_msvc 0.52.6",
"windows_x86_64_gnullvm 0.52.4", "windows_x86_64_gnu 0.52.6",
"windows_x86_64_msvc 0.52.4", "windows_x86_64_gnullvm 0.52.6",
"windows_x86_64_msvc 0.52.6",
] ]
[[package]] [[package]]
@ -8691,9 +8702,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
[[package]] [[package]]
name = "windows_aarch64_gnullvm" name = "windows_aarch64_gnullvm"
version = "0.52.4" version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
[[package]] [[package]]
name = "windows_aarch64_msvc" name = "windows_aarch64_msvc"
@ -8703,9 +8714,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
[[package]] [[package]]
name = "windows_aarch64_msvc" name = "windows_aarch64_msvc"
version = "0.52.4" version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
[[package]] [[package]]
name = "windows_i686_gnu" name = "windows_i686_gnu"
@ -8715,9 +8726,15 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
[[package]] [[package]]
name = "windows_i686_gnu" name = "windows_i686_gnu"
version = "0.52.4" version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
[[package]]
name = "windows_i686_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
[[package]] [[package]]
name = "windows_i686_msvc" name = "windows_i686_msvc"
@ -8727,9 +8744,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
[[package]] [[package]]
name = "windows_i686_msvc" name = "windows_i686_msvc"
version = "0.52.4" version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
[[package]] [[package]]
name = "windows_x86_64_gnu" name = "windows_x86_64_gnu"
@ -8739,9 +8756,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
[[package]] [[package]]
name = "windows_x86_64_gnu" name = "windows_x86_64_gnu"
version = "0.52.4" version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
[[package]] [[package]]
name = "windows_x86_64_gnullvm" name = "windows_x86_64_gnullvm"
@ -8751,9 +8768,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
[[package]] [[package]]
name = "windows_x86_64_gnullvm" name = "windows_x86_64_gnullvm"
version = "0.52.4" version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
[[package]] [[package]]
name = "windows_x86_64_msvc" name = "windows_x86_64_msvc"
@ -8763,9 +8780,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
[[package]] [[package]]
name = "windows_x86_64_msvc" name = "windows_x86_64_msvc"
version = "0.52.4" version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
[[package]] [[package]]
name = "winnow" name = "winnow"

View file

@ -239,7 +239,7 @@ nix = "=0.27.1"
# windows deps # windows deps
junction = "=0.2.0" junction = "=0.2.0"
winapi = "=0.3.9" winapi = "=0.3.9"
windows-sys = { version = "0.52.0", features = ["Win32_Foundation", "Win32_Media", "Win32_Storage_FileSystem", "Win32_System_IO", "Win32_System_WindowsProgramming", "Wdk", "Wdk_System", "Wdk_System_SystemInformation", "Win32_Security", "Win32_System_Pipes", "Wdk_Storage_FileSystem", "Win32_System_Registry", "Win32_System_Kernel"] } windows-sys = { version = "0.59.0", features = ["Win32_Foundation", "Win32_Media", "Win32_Storage_FileSystem", "Win32_System_IO", "Win32_System_WindowsProgramming", "Wdk", "Wdk_System", "Wdk_System_SystemInformation", "Win32_Security", "Win32_System_Pipes", "Wdk_Storage_FileSystem", "Win32_System_Registry", "Win32_System_Kernel", "Win32_System_Threading", "Win32_UI", "Win32_UI_Shell"] }
winres = "=0.1.12" winres = "=0.1.12"
[profile.release] [profile.release]

View file

@ -83,7 +83,7 @@ deno_path_util.workspace = true
deno_resolver.workspace = true deno_resolver.workspace = true
deno_runtime = { workspace = true, features = ["include_js_files_for_snapshotting"] } deno_runtime = { workspace = true, features = ["include_js_files_for_snapshotting"] }
deno_semver.workspace = true deno_semver.workspace = true
deno_task_shell = "=0.20.1" deno_task_shell = "=0.20.2"
deno_telemetry.workspace = true deno_telemetry.workspace = true
deno_terminal.workspace = true deno_terminal.workspace = true
libsui = "0.5.0" libsui = "0.5.0"

View file

@ -407,7 +407,7 @@ pub fn bi_pipe_pair_raw(
&s, &s,
OPEN_EXISTING, OPEN_EXISTING,
FILE_FLAG_OVERLAPPED, FILE_FLAG_OVERLAPPED,
0, std::ptr::null_mut(),
); );
if hd2 == INVALID_HANDLE_VALUE { if hd2 == INVALID_HANDLE_VALUE {
return Err(io::Error::last_os_error()); return Err(io::Error::last_os_error());

View file

@ -0,0 +1,5 @@
{
"if": "windows",
"args": "run --check -A main.ts",
"output": "[WILDCARD]" // just ensure no failure
}

View file

@ -0,0 +1,5 @@
{
"tasks": {
"start": "deno run -A script.js"
}
}

View file

@ -0,0 +1,75 @@
class StdoutReader {
readonly #reader: ReadableStreamDefaultReader<string>;
text = "";
constructor(stream: ReadableStream<Uint8Array>) {
const textStream = stream.pipeThrough(new TextDecoderStream());
this.#reader = textStream.getReader();
}
[Symbol.dispose]() {
this.#reader.releaseLock();
}
async waitForText(waitingText: string) {
if (this.text.includes(waitingText)) {
return;
}
while (true) {
const { value, done } = await this.#reader.read();
if (value) {
this.text += value;
if (this.text.includes(waitingText)) {
break;
}
}
if (done) {
throw new Error("Did not find text: " + waitingText);
}
}
}
}
const command = new Deno.Command("deno", {
args: ["task", "start"],
stdout: "piped",
});
const child = command.spawn();
const reader = new StdoutReader(child.stdout!);
console.log("Waiting...");
await reader.waitForText("Ready");
console.log("Received.");
const pid = parseInt(reader.text.split("\n")[0], 10);
console.log("PID", pid);
// ensure this function works
if (!isPidAlive(child.pid)) {
throw new Error("Unexpected.");
}
if (!isPidAlive(pid)) {
throw new Error("Unexpected.");
}
child.kill();
// now the grandchild shouldn't be alive
if (isPidAlive(pid)) {
throw new Error("Unexpected.");
}
function isPidAlive(pid: number) {
const command = new Deno.Command("cmd", {
args: ["/c", `wmic process where processid=${pid} get processid`],
});
try {
const { stdout } = command.outputSync(); // Execute the command
const output = new TextDecoder().decode(stdout);
console.log("wmic output:", output.trim());
return output.includes(pid.toString());
} catch (error) {
console.error("Error checking PID:", error);
return false;
}
}

View file

@ -0,0 +1,3 @@
console.log(Deno.pid);
console.log("Ready");
setInterval(() => {}, 10_000); // stay alive