tim-kos/node-retry

would be nice to have option to retry indefinitely

davepacheco opened this issue ยท 20 comments

Sometimes, you want to retry an operation indefinitely. It would be nice if "Infinity" (or some other special value) could be specified for "retries". Currently, that causes Node to blow up with out of memory.

For those, who still did not hacked it, here is the solution to continue tryouts with constant timeout after you've reached attempts limit:

if (!operation._timeouts.length) {     // when reached attempts limit
  operation._timeouts[0] = 10*60*1000; // continue trying each 10mins
}                       // do it right before calling operation.retry
if (operation.retry(err)) 
....

Well, you could also put your retry logic into a function and once it returns, because all retries are exceeded, you call that calling function again to start the retry process again.

gunar commented

I'd like to reopen this discussion and have 0 retries mean it should retry indefinitely.

Current implementation is 0 retries equals a single attempt. In my view that's less useful than my suggestion, since if you don't want retries, just don't use node-retry.

What do you guys think? Happy to provide PR.

An option to retry indefinitely is nice. But for what it's worth, we have programs that use node-retry, and sometimes (based on user configuration) don't want to retry at all. It's pretty useful to be able to just write the code to use node-retry for the general case and then specify retries=0 when you want that. Infinity is a valid numeric value and actually reflects what you want (i.e., infinite retries)

gunar commented

@davepacheco Agreed. Infinity would be perfect but doesn't work.

That's because of the way it's implemented now. I thought you were proposing a change to node-retry.

I do also have programs that use 0 so I'm up for infinity. I also think this is a good addition. @tim-kos?

gunar commented

@davepacheco would you mind reopening this issue? Thank you!

@tim-kos what do you think about our proposal? do you want me to open a separate issue? Again, happy to provide a PR. Thanks!

@gunar I don't have permissions to reopen this issue.

I'd like to reopen this discussion and have 0 retries mean it should retry indefinitely.

That's definitely backwards-compatibility breaking, so we can't do that, I am sorry.

what do you think about our proposal? do you want me to open a separate issue? Again, happy to provide a PR. Thanks!

Sure, I have re-opened the issue. Also happy to review and merge a PR. Not sure about infinity, though. But maybe some other value would be cool?

What's wrong with using Infinity?

While it might look strange, Infinity is exactly what we want and it's the best type to express what we really want.. infinite retries.

Okay, haven't used it myself yet in over 12 years, but I hear you. :)

Anybody up for submitting a PR?

Can someone please explain the diference between Infinityand Forever?

Forever? I guess that type doesn't exist.

Oh you are right, this issue is quite old compared to the forever option that was recently added. @tim-kos can you clarify if that new option solves what is being discussed here?

Hey everyone,

Yes, that is exactly what the recently added forever does. There is no specified set of timeouts, but rather a minimum and maximum timeout, which is used again and again until you manually call operation.stop().

Just check the test case here, and it should be quite clear: https://github.com/tim-kos/node-retry/blob/master/test/integration/test-forever.js

Closing this issue then now. ๐Ÿ‘

๐Ÿ‘๐Ÿ‘๐Ÿ‘

Is there an ability to retry forever with increasing time between each attempt rather than a constant timeout? For example, could I start with minTimeout at 1000, use a factor of 2, and then cap the time between intervals at a maxTimeout (allowing retries to continue forever at maxTimeout).