Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: unusable #93

Open
mbrevda opened this issue Nov 6, 2024 · 0 comments
Open

TypeError: unusable #93

mbrevda opened this issue Nov 6, 2024 · 0 comments

Comments

@mbrevda
Copy link

mbrevda commented Nov 6, 2024

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant