Skip to content

Setting retry.calculateDelay option effectively clears other useful retry defaults #1143

Description

@davidtheclark

Describe the bug

  • Node.js version: v12.16.0
  • OS & version: macOS 10.15.3

Setting retry.calculateDelay option effectively clears retry.statusCodes, retry.errorCodes, retry.methods. So if I set retry.calculateDelay, I need to reimplement the status code, error code, and method filters.

I'd love to adjust the backoff algorithm with the retry.calculateDelay option while accepting the defaults for those other options. I like those other defaults, but the default backoff function is too conservative for my use case, and isn't capped.

I'm filing this as a bug because with the current documentation I am surprised by this behavior. Maybe you'd consider it a bug fix to clarify the documentation — in which case this is a feature request.

Is this a new occurrence of #753?

Below I'll explain one specific example of what I'd expect, to illustrate the broader point above:

Actual behavior

If I set a custom retry.calculateDelay function but do not set retry.statusCodes, errors are still filtered according to the default statusCodes values before they reach my retry.calculateDelay function. I will not retry on 404s, for example, even if I don't add any logic to my function to filter out 404s.

Expected behavior

My retry.calculateDelay function is called even if the status code is 404. Essentially, I need to reimplement the default status code, error code, and method filters.

Code to reproduce

const client = got.extend({
  retry: {
    limit: 10,
    calculateDelay: ({ attemptCount }) => {
      // I don't want to reimplement the code & method filters here. 
      if (attemptCount === 1) return 1;
      return Math.min(Math.pow(2, attemptCount) * 50 * Math.random(), 1000);
    },
  },
});

Checklist

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationThe issue will improve the docs

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions