Skip to content
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

AsyncLocalStorage store cleanup callback #57010

Open
eliocapella opened this issue Feb 12, 2025 · 1 comment
Open

AsyncLocalStorage store cleanup callback #57010

eliocapella opened this issue Feb 12, 2025 · 1 comment
Labels
async_local_storage AsyncLocalStorage feature request Issues that request new features to be added to Node.js.

Comments

@eliocapella
Copy link

What is the problem this feature will solve?

Currently I would like to store in AsyncLocalStorage an object that requires clean up. It is a MongoDB session, after the async chain is finished I should execute session.endSession. I have no way to listen when the AsyncLocalStorage is going to be destroyed and execute my clean operation.

What is the feature you are proposing to solve the problem?

I propose the adding a callback argument to the AsyncLocalStorage.run function to be executed at the end of the async chain started there.

What alternatives have you considered?

I've tried using AsyncHooks to try to achieve this but I've unable to achieve this reliably.

@eliocapella eliocapella added the feature request Issues that request new features to be added to Node.js. label Feb 12, 2025
@github-project-automation github-project-automation bot moved this to Awaiting Triage in Node.js feature requests Feb 12, 2025
@eliocapella eliocapella changed the title AsyncLocalStorage destroy hooks AsyncLocalStorage store cleanup callback Feb 12, 2025
@Jamesernator
Copy link

There is a equivalent issue on the proposal that would add (essentially) async locals to JS proper. The stopgap you can use is the same as with that issue, just perform cleanup on the object being garbage collected instead.

@Flarna Flarna added the async_local_storage AsyncLocalStorage label Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
async_local_storage AsyncLocalStorage feature request Issues that request new features to be added to Node.js.
Projects
Status: Awaiting Triage
Development

No branches or pull requests

3 participants