-
Notifications
You must be signed in to change notification settings - Fork 129
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
[useResponseCache] Ensure calls to cache are awaited #2241
base: main
Are you sure you want to change the base?
[useResponseCache] Ensure calls to cache are awaited #2241
Conversation
🦋 Changeset detectedLatest commit: f38e8d5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Thank you for you contribution! Very appreciated! I agree that we should not have floating promises without any error handling here, but I'm not sure that awaiting it is the right approach about this. My concern is that if there is a For this reasons, perhaps just adding a The drawback is that it opens the possibility to have hanging open handles when shuting down the server, which can prevent server for gracefully exit. That being said, it's already the case with the current implementation. We should probably better add an abort signal to allow canceling these promises on shutdown, but not sure it is worth the added complexity for a case that is probably very rare. |
After some discussion with a colleague, it appears that we actually already have a way to handle floating promises like this. |
Adding a As far as logging goes, I'm not sure where |
Sorry, I was not very clear. |
Thanks, could you point us to some documentation for this once it's ready and we'll give it a go? |
Description
This change ensures that the calls to the supplied cache implementation are awaited and returned, in the case that the methods are async and return promises. This prevents "floating promises" from being created which will crash the Node process if they are rejected.
I believe this is not a breaking change since all supported Node versions have the behaviour of terminating on unhandled promise rejections, and that the behaviour without this change is not intentional or desired.
Fixes #2240.
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Unit tests added for
set
andinvalidate
calls to the cache implementation, ensuring that sync errors and promise rejections don't result in process termination.Test Environment:
@envelop/response-cache
: 6.1.2Checklist:
CONTRIBUTING doc and the
style guidelines of this project