fix: EADDRINUSE: address already in use - when a stale SOCKET_PATH file already exists - #15449
Conversation
🦋 Changeset detectedLatest commit: f1cce34 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 |
Conduitry
left a comment
There was a problem hiding this comment.
This feels dangerous. If someone accidentally passes the wrong path in the environment variable, we'd be deleting some random file on their system. I'd prefer it to be the caller's responsibility to make sure that the spot for the socket is clear, the way this works in a number of other tools.
If we do decide we want to do this, I'd be in favor of using rm(path, { force: true }) rather than catching and suppressing one specific error.
yes, it "feels" dangerous. however this is the only way to ensure the node server starts up if there's already an existing file of any sort at the same path as SOCKET_PATH
clearing the SOCKET_PATH before node startup does not fix the edge case where node is running under a supervisor such as BSD daemon(8) and node shuts down or crashes and gets restarted by the supervisor. in that case node goes into a loop unable to start up cuz there's a stale socket file it never cleared because it crashed. as for "other tools", servers such as OpenLDAP's there's plenty of prior art where servers deal with this issue in different ways. however this is a real world issue where node.js has not yet applied the same fix that was fixed in deno v2.6.7: but even that fix does not address the edge case where a stale socket file gets left behind cuz node crashes and never gets a chance to clean up the socket file -- running under a supervisor the node proc will go into a loop unable to fully start up cuz there's a stale socket file in the way. most of the arguments about this have already been hashed out in the denoland thread
agreed -- that does look better. P.S. I'm the one who submitted a similar fix to the NextLegacy/sveltekit-adapter-deno -- I'll make another PR there to do |
|
If something genuinely is a socket file from a previous run, it will have size zero now, correct? What do folks think about statting the file and, if it exists and is zero bytes, automatically deleting it? I think/hope that would be just as usable and low-friction as the current unconditional removal - and it reduces my concerns about deleting the wrong file considerably, as it will just be something with zero bytes. |
|
implemented that change |
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## @sveltejs/kit@2.68.0 ### Minor Changes - feat: expose `RemoteFormEnhanceInstance` and `RemoteFormEnhanceCallback` types ([#15816](#15816)) - feat: set value of `submit` fields when form is submitted ([#15979](#15979)) ### Patch Changes - fix: skip `native_navigation` when `__data.json` returns 404 on a static fallback page ([#16135](#16135)) - fix: ignore third-party monkeypatches in `pushState`/`replaceState` warning detection ([#15267](#15267)) - fix: snapshot form fields on read ([#16150](#16150)) - fix: strip field prefix before erroring on duplicates ([#16151](#16151)) - fix: call reset function via prototype ([#16138](#16138)) - chore: fix navigation `type` hover info ([#16147](#16147)) ## @sveltejs/adapter-node@5.5.7 ### Patch Changes - fix: add `X-Accel-Buffering: no` header to `text/event-stream` responses to prevent reverse proxies such as nginx from buffering streamed responses ([#16156](#16156)) - fix: delete existing socket file on startup ([#15449](#15449)) - Updated dependencies [[`c426c6e`](c426c6e), [`81f253e`](81f253e), [`8d3c865`](8d3c865), [`6bde3b6`](6bde3b6), [`9161740`](9161740), [`2184960`](2184960), [`5e319b6`](5e319b6), [`e82a0a8`](e82a0a8)]: - @sveltejs/kit@2.68.0 Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Replace the size===0 heuristic (which can't distinguish stale from live) with a net.connect() probe. Only remove the socket file when the probe gets ECONNREFUSED; any other outcome (success, timeout, other error) is treated as 'live' so we never destroy an active server's socket. Re-stat and compare inode/dev between probe and rm to close the TOCTOU window in concurrent cold-start scenarios. Removes the cluster.isWorker guard added in 9fd278c, which was correct for Node-native cluster mode but left stale-socket cleanup broken for all PM2 cluster deployments (every process has cluster.isWorker===true there). Fixes sveltejs#15449 sveltejs#16230
Occasionally socket file is not removed when server crashes/shutdown. This patch attempts to delete the file before restarting the server. Applies similar solution as was pulled into adapter-deno package recently:
https://github.com/NextLegacy/sveltekit-adapter-deno
NextLegacy/sveltekit-adapter-deno#1
NextLegacy/sveltekit-adapter-deno#2
To reproduce, create a sock file, and attempt to start the server:
After adding this patch, starting the server succeeds:
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