Skip to content

Commit

Permalink
fix(ext/web): fix AbortSignal.timeout() leak (denoland#23842)
Browse files Browse the repository at this point in the history
<!--
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 denoland#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 denoland#20663.

---------

Co-authored-by: Asher Gomez <[email protected]>
Co-authored-by: Divy Srivastava <[email protected]>
  • Loading branch information
3 people authored and zebreus committed Jul 8, 2024
1 parent d8c97bc commit 630e7a4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
9 changes: 3 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
11 changes: 7 additions & 4 deletions ext/web/03_abort_signal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/timers_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
});

0 comments on commit 630e7a4

Please sign in to comment.