Commit 83e5b94
authored
fix(cli): bind a free port for edge-runtime diff containers (#5424)
## 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 #54071 parent 39bf0e7 commit 83e5b94
3 files changed
Lines changed: 76 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
230 | 230 | | |
231 | 231 | | |
232 | 232 | | |
233 | | - | |
| 233 | + | |
234 | 234 | | |
235 | 235 | | |
236 | 236 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
6 | 8 | | |
7 | 9 | | |
8 | 10 | | |
| |||
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
14 | 41 | | |
15 | 42 | | |
16 | 43 | | |
17 | | - | |
| 44 | + | |
18 | 45 | | |
19 | 46 | | |
20 | 47 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
0 commit comments