Skip to content

Request signal isn't aborted after garbage collection #55428

Open
@jvaill

Description

@jvaill

Bug Description

Passing a signal to Request() and aborting it does not cause the underlying request signal to be aborted after it's been garbage collected. This leads to issues where you want to listen on the request signal even after the request itself falls out of scope - e.g., the request is instantiated with an abort controller signal and downstream code is waiting for that signal to be aborted via request.signal.

Reproducible By

Run the following using node --expose-gc main.js:

const ac = new AbortController();

ac.signal.addEventListener("abort", () => {
  console.log("ac signal aborted");
});

const request = new Request("https://google.ca", { signal: ac.signal });

request.signal.addEventListener("abort", () => {
  console.log("request signal aborted");
});

setTimeout(() => {
  global.gc();
  ac.abort();
}, 0);

Expected Behavior

ac signal aborted and request signal aborted should be logged to the console.

Instead, only ac signal aborted is logged.

Environment

Latest node and undici. Tried it in some older versions as well.

Additional context

A few folks are running into this while trying to close event stream requests in the remix web framework. The underlying requests are never closed because the signal doesn't get aborted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues with confirmed bugs.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions