diff options
author | Tom Alcorn <tdb.alcorn@gmail.com> | 2024-06-18 14:47:05 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-19 07:47:05 +1000 |
commit | 5289c69271fed638571580bfb120c41bd6ea4372 (patch) | |
tree | 9a88f81d6df07a4a6706e66dd97e610b89dd463e | |
parent | cba212b9c63f80b73994cf6012c5db83b31eefc9 (diff) |
fix(ext/web): fix `AbortSignal.timeout()` leak (#23842)
<!--
Before submitting a PR, please read
https://docs.deno.com/runtime/manual/references/contributing
1. Give the PR a descriptive title.
Examples of good title:
- fix(std/http): Fix race condition in server
- docs(console): Update docstrings
- feat(doc): Handle nested reexports
Examples of bad title:
- fix #7123
- update docs
- fix bugs
2. Ensure there is a related issue and it is referenced in the PR text.
3. Ensure there are tests that cover the changes.
4. Ensure `cargo test` passes.
5. Ensure `./tools/format.js` passes without changing files.
6. Ensure `./tools/lint.js` passes.
7. Open as a draft PR if your work is still in progress. The CI won't
run
all steps, but you can add '[ci]' to a commit message to force it to.
8. If you would like to run the benchmarks on the CI, add the 'ci-bench'
label.
-->
Fixes #20663.
---------
Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
Co-authored-by: Divy Srivastava <dj.srivastava23@gmail.com>
-rw-r--r-- | Cargo.lock | 9 | ||||
-rw-r--r-- | Cargo.toml | 3 | ||||
-rw-r--r-- | ext/web/03_abort_signal.js | 11 | ||||
-rw-r--r-- | tests/unit/timers_test.ts | 8 |
4 files changed, 21 insertions, 10 deletions
diff --git a/Cargo.lock b/Cargo.lock index fd5fa22c3..4f0caca3c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1304,8 +1304,7 @@ dependencies = [ [[package]] name = "deno_core" version = "0.289.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e22f78a33feec9a7b211253b0aefbb8cb3b0081483ee8cec7bd954c76ac072a" +source = "git+https://github.com/denoland/deno_core#e0f203688ad98dd18cc079e48e9f2c318899519f" dependencies = [ "anyhow", "bincode", @@ -1763,8 +1762,7 @@ dependencies = [ [[package]] name = "deno_ops" version = "0.165.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "063c6ab08f9275a958878ae54e470cc6ce16f81c1fef16129db0c99d46c5fd35" +source = "git+https://github.com/denoland/deno_core#e0f203688ad98dd18cc079e48e9f2c318899519f" dependencies = [ "proc-macro-rules", "proc-macro2", @@ -5785,8 +5783,7 @@ dependencies = [ [[package]] name = "serde_v8" version = "0.198.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "491380c88077b81b2390e5f0cc10f64860819ba03369bb154bb9e4a587b31a01" +source = "git+https://github.com/denoland/deno_core#e0f203688ad98dd18cc079e48e9f2c318899519f" dependencies = [ "num-bigint", "serde", diff --git a/Cargo.toml b/Cargo.toml index bba40ecc9..fdb20c105 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -368,3 +368,6 @@ opt-level = 3 opt-level = 3 [profile.release.package.base64-simd] opt-level = 3 + +[patch.crates-io] +deno_core = { git = "https://github.com/denoland/deno_core" } diff --git a/ext/web/03_abort_signal.js b/ext/web/03_abort_signal.js index 053b89bdf..81844d53f 100644 --- a/ext/web/03_abort_signal.js +++ b/ext/web/03_abort_signal.js @@ -3,7 +3,7 @@ // @ts-check /// <reference path="../../core/internal.d.ts" /> -import { primordials } from "ext:core/mod.js"; +import { core, primordials } from "ext:core/mod.js"; const { ArrayPrototypeEvery, ArrayPrototypePush, @@ -33,7 +33,7 @@ import { listenerCount, setIsTrusted, } from "./02_event.js"; -import { refTimer, setTimeout, unrefTimer } from "./02_timers.js"; +import { clearTimeout, refTimer, unrefTimer } from "./02_timers.js"; // Since WeakSet is not a iterable, WeakRefSet class is provided to store and // iterate objects. @@ -118,14 +118,17 @@ class AbortSignal extends EventTarget { ); const signal = new AbortSignal(illegalConstructorKey); - signal[timerId] = setTimeout( + signal[timerId] = core.queueSystemTimer( + undefined, + false, + millis, () => { + clearTimeout(signal[timerId]); signal[timerId] = null; signal[signalAbort]( new DOMException("Signal timed out.", "TimeoutError"), ); }, - millis, ); unrefTimer(signal[timerId]); return signal; diff --git a/tests/unit/timers_test.ts b/tests/unit/timers_test.ts index 0b2a66e6e..6e829c07f 100644 --- a/tests/unit/timers_test.ts +++ b/tests/unit/timers_test.ts @@ -767,3 +767,11 @@ Deno.test({ assert(result >= 1000); }, }); + +// Regression test for https://github.com/denoland/deno/issues/20663 +Deno.test({ + name: "regression for #20663", + fn: () => { + AbortSignal.timeout(2000); + }, +}); |