Skip to content

TypeError: unusable #93

Description

@mbrevda

When passing a Request() object to fetch-retry, retries fail with:

node:internal/deps/undici/undici:9658
          throw new TypeError("unusable");
          ^

TypeError: unusable
    at _Request.clone (node:internal/deps/undici/undici:9658:17)
    at wrappedFetch (/tmp/node_modules/fetch-retry/index.js:69:21)
    at Timeout._onTimeout (/tmp/node_modules/fetch-retry/index.js:127:11)
    at listOnTimeout (node:internal/timers:594:17)
    at process.processTimers (node:internal/timers:529:7)

This issue appears in node 2.8.0 that includes undici v6.19.8, which includes this PR which is likely related.

To reproduce, run the following commands, which uses docker to run the test on different versions of node. The 2.7 one should run fine, the 2.8 should fail with the above error:

test.mjs
import retry from 'fetch-retry';

const retryFetch = retry(globalThis.fetch, {
  retryDelay: (attempt) => Math.pow(2, attempt) * 5000,
  retryOn: (attempt, e) => {
    if (attempt >= 5) return false;
    console.log(`fetch: retrying, attempt ${attempt + 1}`, e);
    return true;
  },
});

await retryFetch(
  new Request(
    'https://github.com/fobarba345zfoba345rbazfobarbazfobar2345bazfobar2354bazfobarbazfobarbazfobarbaz',
    {method: 'POST', body: 'foo=bar'},
  ),
);
docker run -it --rm -v./:/tmp node:22.7.0-alpine3.19 node /tmp/test.mjs
docker run -it --rm -v./:/tmp node:22.8.0-alpine3.19 node /tmp/test.mjs

When running locally, here is what I get:

➜  web git:(master) ✗ docker run -it --rm -v./:/tmp node:22.7.0-alpine3.19 node /tmp/test.mjs
fetch: retrying, attempt 1 null
fetch: retrying, attempt 2 null
fetch: retrying, attempt 3 null
fetch: retrying, attempt 4 null
fetch: retrying, attempt 5 null
➜  web git:(master) ✗ docker run -it --rm -v./:/tmp node:22.8.0-alpine3.19 node /tmp/test.mjs
fetch: retrying, attempt 1 null
fetch: retrying, attempt 2 null
node:internal/deps/undici/undici:9658
          throw new TypeError("unusable");
          ^

TypeError: unusable
    at _Request.clone (node:internal/deps/undici/undici:9658:17)
    at wrappedFetch (/tmp/node_modules/fetch-retry/index.js:69:21)
    at Timeout._onTimeout (/tmp/node_modules/fetch-retry/index.js:127:11)
    at listOnTimeout (node:internal/timers:594:17)
    at process.processTimers (node:internal/timers:529:7)

Node.js v22.8.0

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions