fix(settings): treat bracketed IPv6 loopback DATABASE_URL/NATS_URL as local - #5217
Merged
Conversation
pedrofrxncx
enabled auto-merge (squash)
July 24, 2026 18:19
pedrofrxncx
added a commit
that referenced
this pull request
Jul 24, 2026
#5220) The `deco services up/down` externalUrlOrNull had its own copy of the external-host check, missing the bracketed-IPv6 fix landed in #5217 for resolve-config.ts's copy. A bracketed IPv6 loopback DATABASE_URL/NATS_URL (e.g. "postgres://[::1]:5432/postgres") kept the brackets in `URL#hostname`, failed the bare "::1" comparison, and was wrongly treated as external — skipping local Postgres/NATS provisioning. Export the already-fixed, already-tested resolve-config.ts helper and import it in services.ts instead of keeping a second copy.
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.
Source: bug found while auditing
apps/api/src/settings/resolve-config.tsfallback logic (this tick's focus area). Note: PR #5130 already covers the DUCKDB_THREADS validation gap in this file (against its pre-splitapps/meshpath), so this PR targets a different, previously-unhandled gap in the same file.Payoff:
externalUrlOrNulldecides whetherapps/api/src/services/ensure-services.tsskips starting the embedded local Postgres/NATS (skipPostgres/skipNats). It comparesURL#hostnameagainst the bare loopback forms"localhost","127.0.0.1","::1"— but for a bracketed IPv6 URL likepostgres://[::1]:5432/postgres,URL#hostnamereturns"[::1]"(brackets included), so the comparison never matches. ADATABASE_URL/NATS_URLwritten with an IPv6 loopback (a legitimate way to say "local") is misclassified as external, causing the app to skip booting the embedded services it actually needs and instead try to reach a service that was never started.Failure scenario: set
DATABASE_URL=postgres://[::1]:5432/postgres(orNATS_URL=nats://[::1]:4222) —resolveConfigreportsexternalDatabaseUrl/externalNatsUrlas non-null,ensure-services.tssetsskipPostgres/skipNatsto true, and the embedded local Postgres/NATS never starts even though the URL points at localhost.Fix: strip the brackets from
parsed.hostnamebefore comparing, so[::1]normalizes to::1and matches the existing loopback check. Added a regression test covering bracketed-IPv6 DATABASE_URL and NATS_URL (both now correctly resolve tonull/local) plus a genuinely-remote-host case to confirm external detection still works.Verify:
cd apps/api && bun test src/settings/resolve-config.test.ts(53 pass, 0 fail).Checks run locally:
bun run fmt,bunx tsc --noEmit(apps/api workspace, clean), and the targeted test file above. Full CI validates the rest.Summary by cubic
Fixes local URL detection for bracketed IPv6 loopback so
[::1]inDATABASE_URLorNATS_URLis treated as local. This prevents skipping the embedded Postgres/NATS when using IPv6 loopback.URL.hostnamebefore checking for loopback (localhost,127.0.0.1,::1).[::1]inDATABASE_URLandNATS_URL, plus a remote host case.Written for commit ac11803. Summary will update on new commits.