gaxios icon indicating copy to clipboard operation
gaxios copied to clipboard

onRetryAttempt is not awaited / custom back off strategy

Open simllll opened this issue 4 years ago • 5 comments

Even though in the documentation it's stated that onRetryAttempt can return a promise, the promise is not awaited: see https://github.com/googleapis/gaxios/blob/bf6afebe9bb50261d0aed5ae128853f977682773/src/common.ts#L147 and https://github.com/googleapis/gaxios/blob/bf6afebe9bb50261d0aed5ae128853f977682773/src/retry.ts#L79

My challenge is to build a custom retry handler, which checks for retry-after headers and so on.. I see that adding await would maybe change some behaviour for end-users.. so I would instead vote for a property that allows to override the default expoenitial back off handler? Would that be an option? I can prepare a PR in this case.

simllll avatar Oct 22 '21 12:10 simllll

Bascially it would be just here: https://github.com/googleapis/gaxios/blob/bf6afebe9bb50261d0aed5ae128853f977682773/src/retry.ts#L73

to chagne this line to:

const backoff = config.backoffHandler && config.backoffHandler(err) ||  new Promise(resolve => {
    setTimeout(resolve, delay);
  });

and backoffHandler is an optional function that returns a Promise

simllll avatar Oct 22 '21 13:10 simllll

@simllll thank you for the bug report.

bcoe avatar Oct 22 '21 15:10 bcoe

@simllll would this allow for utilizing an exponential backoff retry strategy?

chandlervdw avatar Jan 20 '22 14:01 chandlervdw

Yes, in this case you can do whatever you want to do... Including exponential back off

simllll avatar Jan 20 '22 14:01 simllll

@simllll switched to feature request from bug, since this is requesting an addition to functionality.

Would you be interested in submitting a patch for this functionality?

bcoe avatar Apr 11 '22 19:04 bcoe