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

fix: unref stdin read #23534

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion runtime/tokio_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,13 @@ where
#[cfg(not(tokio_unstable))]
let join_handle = rt.spawn(future);

rt.block_on(join_handle).unwrap().into_inner()
let r = rt.block_on(join_handle).unwrap().into_inner();
// Forcefully shutdown the runtime - we're done executing JS code at this
// point, but there might be outstanding blocking tasks that were created and
// latered "unrefed". They won't terminate on their own, so we're forcing
// termination of Tokio runtime at this point.
rt.shutdown_background();
r
}

#[inline(always)]
Expand Down
5 changes: 5 additions & 0 deletions tests/specs/run/unref_stdin/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Regression test for https://github.com/denoland/deno/issues/22453
{
"args": "run main.js",
"output": "main.out"
}
11 changes: 11 additions & 0 deletions tests/specs/run/unref_stdin/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const { core } = Deno[Deno.internal];
const opPromise = core.read(Deno.stdin.rid, new Uint8Array(10));
core.unrefOpPromise(opPromise);

async function main() {
console.log(1);
await opPromise;
console.log(2);
}

main();
1 change: 1 addition & 0 deletions tests/specs/run/unref_stdin/main.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
Loading