Skip to content
New issue

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

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

Already on GitHub? # to your account

dns and retry with pre-built interceptors error #3901

Closed
haydnhkim opened this issue Nov 29, 2024 · 0 comments · Fixed by #3903
Closed

dns and retry with pre-built interceptors error #3901

haydnhkim opened this issue Nov 29, 2024 · 0 comments · Fixed by #3903
Labels
bug Something isn't working

Comments

@haydnhkim
Copy link

haydnhkim commented Nov 29, 2024

Bug Description

When I use dns and retry with pre-built interceptors, I get no response.
If I keep the process alive as I did when using express, I get the error below.

Reproducible By

import { Agent, setGlobalDispatcher, interceptors } from 'undici';

const { dns, retry } = interceptors;
const agent = new Agent({
  connect: {
    rejectUnauthorized: false,
  },
}).compose([
  dns({
    maxTTL: 60 * 60 * 1000,
    maxItems: 10000,
  }),
  retry({
    maxRetries: 2,
    maxTimeout: 5 * 1000,
  }),
]);

setGlobalDispatcher(agent);

(async () => {
  const todo = await fetch('https://jsonplaceholder.typicode.com/todos/1')
    .then((res) => res.json())
    .catch(console.error);

  console.log(JSON.stringify(todo, null, 2));
})();

Expected Behavior

A response to the request should occur and console.log should be printed.

{
  "userId": 1,
  "id": 1,
  "title": "delectus aut autem",
  "completed": false
}

Logs & Screenshots

The error below does not always occur immediately.
They occur after a period of time after multiple requests without receiving a response.

uncaughtException: TypeError: this[#handler].onError is not a function
    at DNSDispatchHandler.onError (webpack-internal:///(rsc)/../../node_modules/.pnpm/undici@7.0.0/node_modules/undici/lib/interceptor/dns.js:267:23)
    at Request.onError (webpack-internal:///(rsc)/../../node_modules/.pnpm/undici@7.0.0/node_modules/undici/lib/core/request.js:301:27)
    at Object.errorRequest (webpack-internal:///(rsc)/../../node_modules/.pnpm/undici@7.0.0/node_modules/undici/lib/core/util.js:828:13)
    at Socket.onHttpSocketClose (webpack-internal:///(rsc)/../../node_modules/.pnpm/undici@7.0.0/node_modules/undici/lib/dispatcher/client-h1.js:939:10)
    at Socket.emit (node:events:530:35)
    at TCP.<anonymous> (node:net:337:12)
    at TCP.callbackTrampoline (node:internal/async_hooks:130:17)

  Exception origin: uncaughtException
  ⨯ ../../node_modules/.pnpm/undici@7.0.0/node_modules/undici/lib/interceptor/dns.js (267:1) @ DNSDispatchHandler.onError
  ⨯ uncaughtException: [TypeError: this[#handler].onError is not a function]
   265 |       // eslint-disable-next-line no-fallthrough
   266 |       default:
 > 267 |         this.#handler.onError(err)
       | ^
   268 |         break
   269 |     }
   270 |   }

Environment

MacOS Sequoia 15.0
Node.js v 20.17.0
Node.js v 22.11.0

7.0.0-alpha.6 ~ 7.0.0-alpha.8 → Works fine
7.0.0-alpha.9 and later (include stable v7) → Doesn't work. No output to console.log

@haydnhkim haydnhkim added the bug Something isn't working label Nov 29, 2024
@haydnhkim haydnhkim changed the title dns with pre-built interceptors error dns and retry with pre-built interceptors error Nov 29, 2024
This was referenced Dec 16, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant