-
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
Add custom graceful shutdown handler #4528
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, @kanongil what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should support this usage, especially since it only works on node <18.
If you want to continue doing this, you will probably need to find some hacky workaround.
Thanks for the review! 🧡
Just FMI, why would it only work on Node <18? My API currently runs on Node 20.15.1 with |
Hmm, interesting. How do you know it actually works? The test cases we have that exercise the I would be very much interested, if you can produce a test that runs the |
The tests in my API are here: https://github.com/elastic/kibana/blob/8eceb0db4d4edb0da52564ac082859abfc6ed6e7/src/core/server/integration_tests/http/http_server.test.ts#L52-L126 You can tell that I had to change the assertions in the test when upgrading
TBH, I'm not sure why the test suite in this repo doesn't run that code path. According to everything in the code, it should just work. Even adding hacky console logs show that the phase is I can try to spend a couple of extra hours today debugging to find out what happens to that code path. |
I found the culprit! This line closes the listener, so it won't accept more connections after calling According to Node.js docs, it changed its behavior on v19, which is probably why @kanongil recalls different behavior between v18 and 20. I still don't get why my API behaves differently with the latest version of this library, though. But, in any case, it seems like, if we want to provide graceful rejections we might want to subscribe to |
Thank you very much for your efforts! I have used this new knowledge to create a PR #4528, which reverts the |
Thank you! I'll close my PR then 🧡 |
#4473 introduced a piece of logic to immediately destroy the requests during the
stopping
phase:hapi/lib/core.js
Lines 509 to 513 in 22377ee
This caused a breaking change in my API where I have a custom
onRequest
handler that intercepts the request and returns a graceful503
message explaining that the server is going down.I tried to add a custom handler replacement in this PR, but I wanted to cover that piece of code first with the tests. I can't get my head around as to why my new tests are not hitting that code path. Can someone help me to figure it out?
Thanks!