unjs / ofetch

😱 A better fetch API. Works on node, browser and workers.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

FETCH_KEEP_ALIVE not respected when using native fetch

antoinerey opened this issue · comments

Environment

  • Node.js v18.18.2
  • ofetch v1.3.3

Reproduction

Run the following with FETCH_KEEP_ALIVE=true set.

import { fetch } from 'ofetch'

fetch('/wherever')

Describe the bug

Following the documentation on keepalive, it seems that FETCH_KEEP_ALIVE should be able to keep connection open on Node.js. However, it does not seem to work on my side, using Node.js v18.18.2.

We're using native fetch as it's available, and thus I suspect that FETCH_KEEP_ALIVE is not respected in such cases.

Additional context

According to what I understood when reading the code, it seems to confirm my theory. The FETCH_KEEP_ALIVE env variable is not used if globalThis.fetch is defined, and thus never applies to Node.js version where native fetch is available.

CleanShot 2023-11-23 at 17 11 55@2x

Logs

No response