Repository navigation
Commit eeb572a
committed
fix(gateway): keep explicit loopback bind pinned to 127.0.0.1 (#65619)
On macOS, the best-effort canBindToHost("127.0.0.1") preflight in resolveGatewayBindHost can fail intermittently (port temporarily held by another listener, IPv4/IPv6 dual-stack quirks). When that probe returned false for an EXPLICIT bind: "loopback" configuration, resolveGatewayBindHost silently fell back to 0.0.0.0, and the downstream runtime guard in resolveGatewayRuntimeConfig then rejected startup with 'gateway bind=loopback resolved to non-loopback host 0.0.0.0'. Reporter on Mac mini / Node 22.22 / 2026.4.11 saw the Gateway refuse to start after upgrade.
This change makes the explicit loopback branch always return 127.0.0.1; if 127.0.0.1 is truly unbindable, the OS will return a clear bind error at the actual listen() call, which is the correct surface for that rare condition. The runtime guard now sees the loopback address it expects and no longer fails closed for the macOS preflight-flake case.
Other modes are unchanged: 'lan' still returns 0.0.0.0; 'tailnet'/'custom'/'auto' keep their preflight + fallback behavior so container-aware semantics, Tailscale routing, and operator-supplied custom IPs continue to fall back gracefully when they really cannot bind. Only the explicit user-chosen 'loopback' mode now bypasses the preflight, matching the documented contract that 'loopback listens on 127.0.0.1' (docs/gateway/configuration-reference.md).
Verified locally on Windows 11 + Node 22.14: SHA-256 of the patched loopback branch is captured in the PR body. New regression test 'keeps explicit loopback pinned to 127.0.0.1 without preflight (#65619)' uses a vi.spyOn(net, 'createServer') stub that forces every bind probe to error; the function still returns 127.0.0.1 instead of falling back to 0.0.0.0.
Follows clawsweeper review on #65619: 'The narrow maintainable fix is to make explicit loopback return 127.0.0.1 without weakening auto, tailnet, custom, or the runtime guard that prevents unintended network binds.'1 parent 395fbb8 commit eeb572a
2 files changed
Lines changed: 48 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
692 | 692 | | |
693 | 693 | | |
694 | 694 | | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
695 | 730 | | |
696 | 731 | | |
697 | 732 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
241 | 241 | | |
242 | 242 | | |
243 | 243 | | |
244 | | - | |
| 244 | + | |
| 245 | + | |
245 | 246 | | |
246 | 247 | | |
247 | 248 | | |
| |||
256 | 257 | | |
257 | 258 | | |
258 | 259 | | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
264 | 271 | | |
265 | 272 | | |
266 | 273 | | |
| |||
0 commit comments