Skip to content

fix(cli): bind a free port for edge-runtime diff containers#5424

Merged
Coly010 merged 2 commits into
developfrom
fix/edge-runtime-diff-port-collision
Jun 2, 2026
Merged

fix(cli): bind a free port for edge-runtime diff containers#5424
Coly010 merged 2 commits into
developfrom
fix/edge-runtime-diff-port-collision

Conversation

@Coly010
Copy link
Copy Markdown
Contributor

@Coly010 Coly010 commented Jun 2, 2026

What changed

The schema diff path (supabase db pull and friends) executes one-shot scripts — migra, pg-delta, pgcache — by running edge-runtime start --main-service=. inside a container. Both call sites (RunEdgeRuntimeScript in internal/utils/edgeruntime.go and diffWithStream in internal/db/diff/diff.go) launched it with NetworkMode: host but without a --port flag.

edge-runtime start is an HTTP server and always binds a TCP listener. With no explicit port it bound the edge-runtime default port, and with host networking that bind landed directly in the host (Docker VM) network namespace. When the port was already taken — a leftover diff container from an interrupted run, the local stack, or anything else on that port — the bind failed and the container exited 1.

This change adds a shared EdgeRuntimeStartCmd helper that allocates a free host port and passes it as --port, used by both call sites, so concurrent or leftover one-shot containers no longer contend for the default port. On the rare port-allocation failure it falls back to the previous portless command.

Why

Reported in #5407: supabase db pull on Windows fails at "Diffing schemas..." with Error: Address already in use (os error 98). Host networking on Docker Desktop (Windows/macOS) shares the VM namespace and makes the default-port collision far more likely. functions serve was never affected because it already passes an explicit --port (serve.go:190).

Reviewer notes

  • Covers all diff engines that go through RunEdgeRuntimeScript: migra, pg-delta (×3), pgcache, apply — plus the streaming diffWithStream.
  • With Docker Desktop host networking the port is probed on the real host while the bind happens in the VM namespace, so a probed-free port isn't strictly guaranteed free in the VM. Moving off the single shared default to a random ephemeral port removes virtually all real-world collisions; a fully bulletproof fix would be moving these containers to bridge networking with port mapping (like serve.go), which can follow separately.

Fixes #5407

The schema diff path runs `edge-runtime start` to execute one-shot
scripts (migra, pg-delta, pgcache) with host networking but without a
`--port` flag, so the runtime's HTTP listener bound the edge-runtime
default port directly in the host network namespace. When that port was
already in use (a leftover diff container, the local stack, or anything
else on the port) the bind failed with "Address already in use (os error
98)" and the container exited 1, surfacing as
`error diffing schema: error running container: exit 1`.

Allocate a free host port and pass it as `--port` via a shared
`EdgeRuntimeStartCmd` helper used by both `RunEdgeRuntimeScript` and
`diffWithStream`, so concurrent or leftover one-shot containers no longer
collide on the default port.

Fixes #5407
@Coly010 Coly010 requested a review from a team as a code owner June 2, 2026 10:36
@coveralls
Copy link
Copy Markdown

coveralls commented Jun 2, 2026

Coverage Report for CI Build 26814852769

Coverage increased (+0.001%) to 63.906%

Details

  • Coverage increased (+0.001%) from the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • 8 coverage regressions across 2 files.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

8 previously-covered lines in 2 files lost coverage.

File Lines Losing Coverage Coverage
internal/utils/git.go 5 53.33%
internal/utils/edgeruntime.go 3 90.7%

Coverage Stats

Coverage Status
Relevant Lines: 15792
Covered Lines: 10092
Line Coverage: 63.91%
Coverage Strength: 7.08 hits per line

💛 - Coveralls

@Coly010 Coly010 self-assigned this Jun 2, 2026
@Coly010 Coly010 merged commit 83e5b94 into develop Jun 2, 2026
30 checks passed
@Coly010 Coly010 deleted the fix/edge-runtime-diff-port-collision branch June 2, 2026 11:23
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.

report bug crash ID ed0f14b3d82f47d7bdbaed5bc0d7dc22

3 participants