feat: graceful shutdown and systemd socket activation in adapter-node#11653
feat: graceful shutdown and systemd socket activation in adapter-node#11653benmccann merged 51 commits intosveltejs:mainfrom
Conversation
🦋 Changeset detectedLatest commit: d8c8a90 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 |
Rich-Harris
left a comment
There was a problem hiding this comment.
LGTM but I had one question
Co-authored-by: Conduitry <git@chor.date>
Conduitry
left a comment
There was a problem hiding this comment.
Thank you for your patience during the protracted review process - let's ship it!
|
I'm having issues with this - in particular when connecting to a database (mongodb). Out of the box it works fine via "npm run dev", but hangs if I build with adapter-node and run with node. Maybe I'm doing something dumb, but if there some best practice here ? |
|
Let's please keep the conversation about this in one thread. I've already replied in the other thread and I saw your follow up comment but it can take a few days for me to get back. You can also ask on the Svelte Discord server and ping me there |
|
Just in case others come across this, here's the other thread: #9540 (comment) |
Closes #10134
Closes #9540
This is an alternative PR to #10977 that addresses all the points mentioned there, mainly:
IDLE_TIMEOUTIt also gracefully shuts down the app by default. A new
SHUTDOWN_TIMEOUTenvironment variable controls how long the app should wait for all remaining requests to finish before the server is forcibly closed.If you are on Linux or have access to a Linux server you can try this out yourself by installing the adapter into a new/existing SvelteKit project (requires npm, pnpm doesn't work) using:
Then create a service and socket unit:
Reload the daemon:
Start the socket:
Navigate to
localhost:3000. The app should then start as soon as the first request is made. IfIDLE_TIMEOUTis set it will automatically terminate the app after being inactive forIDLE_TIMEOUTseconds. You can verify this behavior by following the logs usingsudo journalctl -u myapp.service -f.Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm testand lint the project withpnpm lintandpnpm checkChangesets
pnpm changesetand following the prompts. Changesets that add features should beminorand those that fix bugs should bepatch. Please prefix changeset messages withfeat:,fix:, orchore:.Edits