-
Notifications
You must be signed in to change notification settings - Fork 53
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
bail should prevent any further calls to the retrier function #69
Comments
I'm facing a similar issue |
I might be running into this as well....would it occur if calling bail() inside a try/catch block within the retrier? |
Yes, if the call to bail() is followed by code that might throw before returning. |
I've done this, and it seems to be working. The synopsis of all this is: the
|
Yes, of course that if you do The actual issue is when you don't do that. More specifically, after calling bail() it should not matter what the outcome of the returned promise is, it should stop retrying even if you do bail() + throw. |
Were just hit by that as well. Surprising number of unexpected background requests in runtime, while all unit tests were green :) can be caught while unit testing with something like: // `retryer` being a wrapper that retries `request`, similar to the one above in the comments
it("rejects with passed function error and doesn't make more calls than needed", async () => {
request.rejects(new Error("custom error"));
assert.isRejected(retryer(), "custom error"); // actual call to the retrier, pass, rejected
sinon.assert.callCount(request, 1)) // pass, just one call so far
// that was added to catch this issue
return await new Promise(resolve => {
// wait to see if there any retries in the background
// even if the call was rejected
setTimeout(() => {
resolve(sinon.assert.callCount(request, 1)); // will fail, as more requests will be done
}, 500);
});
}); |
I've faced the same issue and for me it feels like an unexpected behaviour. I think that retries should be simply stopped after Pattern provided in README example breaks TypeScript typings: if (403 === res.status) {
// don't retry upon 403
bail(new Error('Unauthorized'))
return
} which leads to an awful type-casting e.g. if (403 === res.status) {
// don't retry upon 403
bail(new Error('Unauthorized'))
return (null as unknown) as PromiseReturnType;
} |
I agree with @przemyslaw-wlodek - the Typescript typings are not great. It would be great if bail had the type of |
just found this issue before pushing my code to prod. any plan to get this fixed? it's been 2 years since the issue was reported. |
Bumping this, we would love to have this thing fixed |
+1 :( |
I think this wrapper should do it. Once bailed, it won't retry.
|
Is this actually still an issue? I wrote these Jest tests that pass, which suggest it works just fine:
|
@agalatan any chance of you opening a PR? I really would love to have this thing fixed :D |
From the example:
Calling bail will immediately reject the promise returned by
retry
, but if the promise returned by the retirer function is then itself rejected, attempts will continue running in the background until e.g. the max retry count is reached.This can be surprising and result in obscure bugs.
The text was updated successfully, but these errors were encountered: