Skip to content

Conversation

@trivenay
Copy link
Contributor

@trivenay trivenay commented Dec 3, 2025

Issue #, if available: JS-6397

Description of changes:
Fixes a bug in InvokeStoreSingle.run() where the try-finally block was clearing the context immediately when the function returned a Promise, before async operations completed. This caused the context to become undefined after any await statement.

Changes:

  • Removed try-finally block from InvokeStoreSingle.run() method
  • Added test case invoke-store.async-context.spec.ts to verify context persists during async operations

Testing:

  • New test verifies context is maintained after await statements
  • Test fails with the buggy code (returns "-" instead of request ID) and passes with the fix

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@trivenay trivenay requested a review from a team as a code owner December 3, 2025 15:07
@changeset-bot
Copy link

changeset-bot bot commented Dec 3, 2025

🦋 Changeset detected

Latest commit: 5aee9a2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@aws/lambda-invoke-store Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Member

@godcrampy godcrampy left a comment

Choose a reason for hiding this comment

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

LGTM.

try {
return fn();
} finally {
this.currentContext = undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

is there any risk to not freeing this reference?

You could use a weakRef instead

Copy link
Contributor Author

@trivenay trivenay Dec 3, 2025

Choose a reason for hiding this comment

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

Hey when we run each time we set the context , so it should be fine -> Making it undefined is anyways not going to be helpful

@kuhe kuhe merged commit b101e20 into awslabs:main Dec 3, 2025
3 checks passed
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.

3 participants