diff options
-rw-r--r-- | runtime/tokio_util.rs | 8 | ||||
-rw-r--r-- | tests/specs/run/unref_stdin/__test__.jsonc | 5 | ||||
-rw-r--r-- | tests/specs/run/unref_stdin/main.js | 11 | ||||
-rw-r--r-- | tests/specs/run/unref_stdin/main.out | 1 |
4 files changed, 24 insertions, 1 deletions
diff --git a/runtime/tokio_util.rs b/runtime/tokio_util.rs index 6ae81167e..da6e8b221 100644 --- a/runtime/tokio_util.rs +++ b/runtime/tokio_util.rs @@ -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)] diff --git a/tests/specs/run/unref_stdin/__test__.jsonc b/tests/specs/run/unref_stdin/__test__.jsonc new file mode 100644 index 000000000..7ba4b54e7 --- /dev/null +++ b/tests/specs/run/unref_stdin/__test__.jsonc @@ -0,0 +1,5 @@ +// Regression test for https://github.com/denoland/deno/issues/22453 +{ + "args": "run main.js", + "output": "main.out" +} diff --git a/tests/specs/run/unref_stdin/main.js b/tests/specs/run/unref_stdin/main.js new file mode 100644 index 000000000..db722bd13 --- /dev/null +++ b/tests/specs/run/unref_stdin/main.js @@ -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(); diff --git a/tests/specs/run/unref_stdin/main.out b/tests/specs/run/unref_stdin/main.out new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/tests/specs/run/unref_stdin/main.out @@ -0,0 +1 @@ +1 |