Skip to content

chore: dynamic ports in dev-mode#164

Closed
atilafassina wants to merge 4 commits intomainfrom
dev/dynamic-port
Closed

chore: dynamic ports in dev-mode#164
atilafassina wants to merge 4 commits intomainfrom
dev/dynamic-port

Conversation

@atilafassina
Copy link
Copy Markdown
Contributor

@atilafassina atilafassina commented Mar 5, 2026

Summary

The dev server prefers port 8000 (or DATABRICKS_APP_PORT if set) and falls back to an OS-assigned free port on EADDRINUSE whenever it's in dev mode without a code-level port pin. This lets a second pnpm dev start without colliding with an already-running one.

DATABRICKS_APP_PORT is treated as a preference in dev (warns and falls back if busy). A code-level server({ port }) is a strict pin (throws on EADDRINUSE) so explicit configuration choices aren't masked. Prod is always strict.

Behavior matrix

Scenario Behavior
Prod (DATABRICKS_APP_PORT set by platform) Bind it. EADDRINUSE → throw.
Dev, no env, no config Try 8000. EADDRINUSE → warn → bind OS-assigned port.
Dev, DATABRICKS_APP_PORT=8001 Try 8001. EADDRINUSE → warn → bind OS-assigned port.
Dev, server({ port: 3000 }) Bind 3000. EADDRINUSE → throw.
Any non-EADDRINUSE error Always throws.

The actually-bound port is logged via server.address() so the OS-assigned port is visible to the developer.

Test plan

  • pnpm test — all suites pass
  • pnpm typecheck — clean
  • pnpm check — clean
  • CI integration tests pass (Playwright on port 8000)
  • Manual: run two pnpm dev instances simultaneously; the second warns and binds a different port; the bound port is visible in the startup log

Dev server tries the preferred port (DATABRICKS_APP_PORT or 8000) and
on EADDRINUSE retries on port 0 when no explicit pin is provided.
Explicit pins (env or `port` config) and non-EADDRINUSE bind errors
always throw, so prod and pinned dev never silently drift.

Co-authored-by: Isaac
Signed-off-by: Atila Fassina <atila@fassina.eu>
In dev, DATABRICKS_APP_PORT=N now means "try N first." If N is busy,
warn and fall back to an OS-assigned port. A code-level
`server({ port })` config remains a strict pin (throws on EADDRINUSE).

Co-authored-by: Isaac
Signed-off-by: Atila Fassina <atila@fassina.eu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant