got icon indicating copy to clipboard operation
got copied to clipboard

statusCodes does not properly limit which requests are retried

Open Inrixia opened this issue 3 years ago • 10 comments

Describe the bug

Setting the statusCodes property on retry should ensure that only responses which match that code are retried. However I am seeing retries for statusCodes not specified.

  • Node.js version: v19.0.0
  • OS & version: Win11

Actual behavior

Non 429 responses are retried.

Expected behavior

Only 429 responses are retried

Code to reproduce

got.extend({
            retry: {
                limit: 5,
                calculateDelay: ({ attemptCount, error }) => {
                    // Retry after the number of seconds specified in the "retry-after" header
                    const retryAfter = error.response?.headers?.["retry-after"];
                    if (retryAfter !== undefined)
                        return parseInt(retryAfter) * 1000; // Convert to milliseconds
                    // Default retry delay
                    return 1000 * attemptCount;
                },
                statusCodes: [429], // Retry on 429 status code
            },
        })

Checklist

  • [x] I have read the documentation.
  • [x] I have tried my code with the latest version of Node.js and Got.

Inrixia avatar Mar 25 '23 14:03 Inrixia

The limit variable also does not apply at all!

Inrixia avatar May 01 '23 04:05 Inrixia

I have the same issue. My retry config: const retry = { retries: RETRY_ATTEMTS, calculateDelay: () => RETRY_DELAY, statusCodes: [102], errorCodes: ['ECONNRESET'], methods: ['POST'], }

I still get retries on 500 errors for example. Got version: 11.8.6 Node version: 18.12.1

cillen avatar Jun 22 '23 08:06 cillen

The only fix for this so far is to check the status code in the function itself and return nothing (which does not retry) if it's not a code you want.

That's not to say this shouldn't be fixed though.

Inrixia avatar Jun 22 '23 08:06 Inrixia

If you omit the calculateDelay in the retry config, the statusCodes limit works, but the retries limit stil does not apply. const retry = { retries: RETRY_ATTEMTS, // calculateDelay: () => RETRY_DELAY, statusCodes: [102], errorCodes: ['ECONNRESET'], methods: ['POST'], }

cillen avatar Jun 23 '23 06:06 cillen

Any chance there will be a fix for this any time soon?

cillen avatar Jun 26 '23 08:06 cillen

My original report of this is 3 months old so I'm very doubtful. For now ig just ignore the feature and manually implement it.

Inrixia avatar Jun 26 '23 17:06 Inrixia

Ok bummer. It would have been neat to use the config instead of manually wrap the call. Well well..

cillen avatar Jun 28 '23 10:06 cillen

Same issue here, sigh.

diVid3 avatar Aug 31 '23 08:08 diVid3