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

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

Closed
EAGzzyCSL opened this issue Dec 19, 2024 · 0 comments · Fixed by #3967
Closed

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

EAGzzyCSL opened this issue Dec 19, 2024 · 0 comments · Fixed by #3967
Labels
bug Something isn't working

Comments

@EAGzzyCSL
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant