Skip to content

Conversation

@developertom01
Copy link

@developertom01 developertom01 commented Aug 20, 2024

  • In my application, I needed to optionally add AbortSignal to terminate retry logic.
  • This PR implements the ability to pass an AbortSignal to the retry logic. This will allow the user to cancel the retry logic if needed.
  • To support AbortConroller in typescript types, I bumped @types/node to 22.4.1 version

@developertom01 developertom01 changed the title Add Abort Signal Implementation Feat: Add Abort Signal Implementation Aug 20, 2024
@louis-bompart louis-bompart self-requested a review February 4, 2025 21:13
@samisayegh
Copy link
Contributor

samisayegh commented Feb 4, 2025

Could you describe the scenario that requires using the Abort API? Some pseudocode could be helpful,

Is it possible to end the retry by returning false in the retry function?

@kagtua
Copy link

kagtua commented Feb 26, 2025

Could you describe the scenario that requires using the Abort API? Some pseudocode could be helpful,

Is it possible to end the retry by returning false in the retry function?

Maybe react useEffect?

useEffect(() => {
    backOff(() => {}, { signal: signal })

    return () => { signal.abort()  }
}, [id])

@bliu13
Copy link

bliu13 commented Feb 26, 2025

My use case is for a polling script that has a graceful shutdown function where receiving a SIGTERM will start cleaning up and sending a signal to abort. The graceful shutdown also has a timeout to exit if everything isn't cleaned up by then.

For a more specific scenario, the built-in fetch API takes in an Abort signal to stop the http request. Normally this wouldn't be an issue, but if you wrap this retry library around the fetch call, this library will go through all the retries, which may be lengthy. If the library can handle the same signal that was passed to the fetch API, then the library could also abort the retrying.

Copy link

@AiSocialNinjaLabs AiSocialNinjaLabs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe I need this same commit for my application?

Caution

working with large data sometimes needs these kinds of fixes in order to maintain repository health.
@AiSocialNinjaLabs, reference #70 @heyppen

Ninja-dev-logo-big-rope

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have been on my developers 👨🏻‍💻 quest for some time now. I have no formal training or education🏛️. I never graduated high school💸, the reason for that is they never had anything I found valuable for my future unfortunately, it wasn’t for lack of trying.and the only reason I had gotten my GED was to join the military(“Best decision of my life to be of service to my country! Hoah!”💯) Anyways, not that any of this really matters to most of you reading this, but, for the one special one like me… Like us… This is for you! I’m just feeling some kind of way right now and I wanted to leave this for any other intuit_dev.soldiers out there that might “accidently”😁, stumble across this… I am self taught on everything. So don’t give up! Your intuition will set you free if you can believe and trust yourself. It’s a lot harder than people will ever know. I am the Ninja-man™🥷
and this is the GhostWriters declaration of pointlessness to those that don’t really matter and as a matter of fact it is for the ones who really do matter, to anyone who actually gives a f@$#! out there! Lastly I GOT MAD LOVE AND RESPECT FOR ALL OPEN SOURCE AND ESPECIALLY GITHUB! THANK YOU AND GOod evening… Social Ninja vanish!🥷😶‍🌫️?

}

throw new Error("Something went wrong.");
throw new Error(this.isAborted ? "Retry aborted" : "Something went wrong.");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my only gripe is not using signal.reason if available. That would be a bit of a refactor here, but I don't think we'd want to NOT use one of the built in values of the AbortController.

I think its reasonable that the reason would populate into the error here to be handled, as well as a separate handling of that inside the catch

const shouldRetry = await this.options.retry(e, this.attemptNumber);

if (!shouldRetry || this.attemptLimitReached) {
if (!shouldRetry || this.isAborted || this.attemptLimitReached) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's not correct to do an abort in between executions - same behavior could be achived in user-defined retry method. Instead setTimeout located here, should be cleared.

@kav
Copy link

kav commented Aug 29, 2025

Happy to pick up addressing the code review if @developertom01 has moved on to other things in the last year.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants