Visitar URL original
Is retry interceptor only retry http error and ignore dns error? · Issue #3966 · nodejs/undici · GitHub
Skip to content

Is retry interceptor only retry http error and ignore dns error? #3966

Closed

Description

@EAGzzyCSL

Bug Description

I found undici built-in retry interceptor will only retry http error and ignore dns error. Is this a bug or feature?

Reproducible By

const { interceptors, Client } = require('undici');
const { retry } = interceptors;

(async () => {
  const client = new Client().compose(
    // httpbin/status/500 will return http status 500 so retry callback will trigger
    'https://httpbin.org',
    // x.y.z is a not reachable server will cause a ENOTFOUND error
    // but will not trigger retry callback
    // 'https://x.y.z',
    retry({
      retry: (err, { state, opts }, done) => {
        console.log('#retry-callback triggered');
      },
      errorCodes: ['ENOTFOUND'],
    }),
  );

  const response = await client.request({
    method: 'GET',
    path: '/status/500',
    headers: {
      'content-type': 'application/json',
    },
  });
})();
  • undici version: 7.1.1

Expected Behavior

Retry callback log be triggered whether host is httpbin.org or x.y.z.

But actual behavior is only httpbin.org will trigger retry.

Logs & Screenshots

Environment

  • Node.js v22.11.0

Additional context

According to the retry-handler doc, retry handler has an option errorCodes means "Array of Error codes to retry", so retry dns error is expected in design?

But in code, retry handler will skip retry in onResponseError hook when controller is falsy.

Controller was pass to onResponseError hook in onError hook,

but controller was only initialized at onConnect hook.

I guess there is no connection established when dns error, so onConnect will not be trigger, which leading controller is undefined.

Activity

  1. added a commit that references this issue on Dec 19, 2024
  2. added a commit that references this issue on Dec 19, 2024
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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions