#11240·axios

fetch adapter: response-stream capability probe leaks an uncancelled ReadableStream

Author: bdcarrCreated Sep 21, 2026Updated Sep 21, 2026

Describe the bug

The fetch adapter's supportsResponseStream capability probe creates a ReadableStream and never cancels it, leaking one pending promise per module realm.

This is the sibling of #7515, which fixed the same defect in the supportsRequestStream probe. That fix shipped in 1.14.0; the response probe was not covered and still leaks in 1.20.0.

javascript
// lib/adapters/fetch.js
const supportsResponseStream =
  isResponseSupported &&
  isReadableStreamSupported &&
  test(() => utils.isReadableStream(new Response('').body));   // never cancelled

new Response('').body creates a ReadableStream whose internal pull pipeline is set up but never consumed or cancelled, so its pull promise stays pending for the lifetime of the realm — the mechanism described in #7515.

Reproduction

https://github.com/bdcarr/axios-fetch-probe-leak

bash
pnpm install
pnpm test        # vitest run --detect-async-leaks

The readme has more details about how the repro works, and a script to test before/after the proposed fix.

Impact at scale

One leak per module realm means one per test file. On the 256-file suite in which I encountered this issue, counting only leaks whose stack originates in axios:

axios axios-attributed leaks
1.13.2 (before #7515) 182
1.20.0 (after #7515) 89
1.20.0 + the change below 4

Roughly one per file in each case — 1.13.2 leaks both probes, 1.20.0 only this one.

Proposed fix

Mirror #7515: keep a reference to the probe body and cancel it once the capability has been read. With this applied the repro reports no leaks and the 256-file suite drops from 89 axios-attributed leaks to 4.

Worth doing the cleanup as an explicitly best-effort helper shared with the request probe, rather than the bare probeBody.cancel() the request probe uses today:

javascript
const cancelProbeBody = (body) => {
  if (body == null) {
    return;
  }

  try {
    const cancelled = body.cancel();

    if (cancelled && isFunction(cancelled.then)) {
      cancelled.then(undefined, () => {});
    }
  } catch (e) {
    // Ignored: an uncancellable probe body only leaks, it is still a valid body.
  }
};

isReadableStream is a toStringTag check rather than a structural one, so a custom env.Request/env.Response can expose a stream-like body with no working cancel. Two things fall out of that, and both apply to the existing request probe as well as this one:

  • a cancel() that throws synchronously escapes into test(), which turns it into false. So the naive fix silently downgrades a capability that was previously detected as supported.
  • a cancel() that rejects produces an unhandled rejection, since the returned promise is dropped.

I checked both against Node 22. A native new Response('').body.cancel() always fulfils, so this only bites custom or polyfilled implementations, but env.Response is a supported injection point so it seems worth guarding.

Environment

axios     1.20.0 (present since the probe was introduced; 1.13.2 leaks both probes)
Adapter   fetch
Vitest    4.1.11
Node      v22.16.0
OS        macOS 26.6.2 arm64

Here is your AI disclosure: :surfer: :)