-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Unexpected change in request lifecycle in 20.2.1 #4420
Comments
This was supposed to be a bug, marked as support by mistake. |
Sorry for mentioning directly, I believe this issue is being neglected because of the wrong label. |
This is pretty tricky— if the request is aborted, then So that's the tension: on one hand, the finalize response steps and At the same time, I totally see how this poses an issue for you. My recommendation would be to handle this case by checking if the request is active after you setup the database connection, and if it isn't then you can tear it down immediately: server.ext('onRequest', async (req, h) => {
req.app.db = await setupDbConnection();
if (!req.active()) {
await req.app.db.close();
}
return h.continue;
}); |
Thank you for the explanation. I agree that both variants are acceptable. However, it seems odd to me to make this change in the patch version. If this change was intentional, then I believe the issue is resolved. |
Support plan
Context
What I am trying to achieve
I'm using
onRequest
andonPostResponse
events to open and close connections with database. ExpectingonPostResponse
to always trigger afteronRequest
.But in #4295 this behavior changes, and
onPostResonse
is able to fire beforeonRequest
(if request is aborted).This behavior does not match with request lifecycle documentation.
Steps to reproduce:
I'm using this go script
What was the result you got?
What result did you expect?
The text was updated successfully, but these errors were encountered: