fix(cli): do not crash writing the dev lock file with a non-loopback --host - #17529
Open
QVinto wants to merge 2 commits into
Open
fix(cli): do not crash writing the dev lock file with a non-loopback --host#17529QVinto wants to merge 2 commits into
--host#17529QVinto wants to merge 2 commits into
Conversation
…-host `astro dev --host <custom-address>` bound to a specific non-loopback address crashed with `Invalid URL` right after the server had started successfully. Vite only reports a `local` URL for loopback hosts; for a specific non-loopback address the URL is reported under `network` and `local` is empty. Reading `resolvedUrls.local[0]` unconditionally therefore passed `undefined` to `new URL()`, killing a dev server that was otherwise up and serving. Extract `resolveLockFileUrl()`, which prefers the local URL and falls back to the network one. When no URL is resolvable at all it returns `null` and the lock file is skipped, so bookkeeping can no longer take down a running server. Fixes withastro#17527
🦋 Changeset detectedLatest commit: 2a75355 The changes in this PR will be included in the next version bump. This PR includes changesets to release 399 packages
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 |
1 task
Smoke (windows-2025) failed in the docs-translation cleanup step with STATUS_DLL_INIT_FAILED (0xC0000142) before any test ran; empty commit to re-run CI.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
Fixes #17527 —
astro dev --host <custom-address>bound to a specific non-loopback address crashed withInvalid URLimmediately after the server had started successfully.Vite only reports a
localURL for loopback hosts. For a specific non-loopback address the URL is reported undernetworkandlocalis left empty:So
resolvedUrls.local[0]wasundefinedandnew URL(undefined)threw while writing the dev lock file, taking down a server that was already up and serving.Extracts
resolveLockFileUrl(), which prefers the local URL and falls back to the network one. Loopback hosts keep recording exactly the URL they did before.When neither array yields a usable URL it returns
nulland the lock file is skipped, so lock file bookkeeping can no longer kill a healthy dev server. Such an instance is simply untracked byastro dev stop/status/logs, the same as--ignore-lock.Only the bare
--host(which binds0.0.0.0and still resolves a local URL) was unaffected, which is why this slipped through — the documented--host <custom-address>form is exactly the one that broke.Changeset included (
patch).Testing
New unit tests in
packages/astro/test/units/dev/lockfile-url.test.ts(6 cases: local present, local preferred over network, network fallback, non-default protocol preserved, both empty →null, unparseable URL →nullrather than a throw). Existingignore-lock-flag,lockfileanddev-outputunit suites still pass.Verified end-to-end against
examples/basicswith the built package. Before the fix the last row crashed; the others are unchanged:dev.jsonurlInvalid URLhttp://localhost:9310--hosthttp://localhost:9311--host 127.0.0.1http://127.0.0.1:9312--host localhosthttp://localhost:9313--host 0.0.0.0http://localhost:9314--host 100.100.30.30http://100.100.30.30:9315astro dev statusandastro dev stopboth work against a server started with a non-loopback--host, andstatuslists the network URL.Docs
No docs change needed — this restores the documented behaviour of
--host <custom-address>("Expose on a network IP address at<custom-address>") rather than changing it. No flags, output shape or lock file fields were added or removed.