Skip to content

fix(server)!: await graceful HTTP shutdown and restart races (10/11) - #90

Closed
ofriw wants to merge 3 commits into
rs/cli-after-pathfrom
rs/http-after-cli
Closed

ofriw wants to merge 3 commits into
rs/cli-after-pathfrom
rs/http-after-cli

Conversation

@ofriw

@ofriw ofriw commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Scope and dependency

Layer 10/11 of the verified replacement for #66 / stack #80. Base: #89. Review and integrate bottom-up; each complete PR tip passes all runtimes without a later unpublished fix.

  • Make stop awaitable and graceful; handle start/stop/restart races, timeout, force and retry after failed teardown.
  • Carry awaitable shutdown through Server and debug/CLI templates; preserve normalized path ingress.
  • Test actual listeners and in-flight requests. A test-only origin helper uses the public bound address to avoid macOS IPv4/IPv6 port collisions and support IPv4-only listeners.

Contract and migration

Breaking: await HttpServerInstance.stop() and Server.stop() (Promise). New requests during drain receive 503/connection: close. Default timeout is 10s; timeoutMs must be an integer 0..2147483647. Force/timeout do not cancel application handlers. ALB health checks accept http/https/any port/query but require exactly lowercase /healthy; use lowercase probe paths.

Verification — 3315ed8baf7a852245c450cf7dcec27292bf71c4

Verified locally on this exact tip with current Deno 2.9.1 and the actual floor 2.3.3 executable, Node 24.14.1, and Playwright 1.64.1/Chromium. The full Deno, Node and browser suites ran separately for each Deno version. Public+worker checks and repeated generated-asset builds passed on both versions. These are measured local gates, not a claim that remote Actions have completed.

Suite Current Floor
Deno 740/740 740/740
Node 740/740 740/740
Browser 435/435 435/435

All reported cases passed. Before #91 the inherited runner counts some runtime-gated early returns as passes; these totals do not claim explicit skip accounting. Summaries and nonzero counts were checked, not exit status alone.

Additional gates on both versions: three targeted Node HTTP35/35 and NodeHTTP6/6 repetitions, plus Deno HTTP35/35. Real IPv4, IPv6 and controlled macOS overlapping-listener probes passed. No production bind API was added.

Review boundary

All 49 source commits in 2be88b35..23d6c6d0 were independently audited across this replacement; the final combined tree also passed review. Intentional departures are co-located: real verification prerequisites, browser path coverage, restored registry guard, portable HTTP tests, and truthful skip display. No binary codec or protected AGENTS/CLAUDE/README changes.

Changed-code checks passed without new diagnostics or suppressions. Inherited broader lint/test-fixture type errors remain; this is not a repository-wide lint/typecheck-clean claim. The final broader changed-file lint has 23 inherited diagnostics. No remote merge or issue edit is part of this replacement.

Stack: https://github.com/goatplatform/goatdb/stack/92

ofriw added 3 commits October 29, 2026 14:38
Root cause of the intermittent HttpServerStop/floor-Node flake: macOS
SO_REUSEADDR lets foreign local listeners inside the ephemeral range
(e.g. Spotify wildcard IPv4 :57621, Chrome-specific 127.0.0.1:54677)
silently overlap our listener bind. Node's default listen uses the
dual-stack IPv6 wildcard, and 127.0.0.1 traffic then gets delivered to
the foreign process (measured: status 200 with foreign body), making
127.0.0.1-based test reads fail. Deno rejects the overlap with
EADDRINUSE and binds the IPv4 wildcard, so 127.0.0.1 stays correct.

Fix is test-only: clients read from the loopback family matching the
bound listener ([::1] for Node, 127.0.0.1 for Deno). No server or
public API change; wildcard bind behavior is unchanged.

Evidence: 2000-cycle stress reproduces an empty-body 200 on 127.0.0.1
(cycle 1169, foreign port 54677) while [::1] completes 2000/2000.
Use one shared public-address helper for both HTTP suites. Capture origins before stop clears the listener, and resolve fresh origins after restart. IPv4-only Node listeners no longer receive IPv6 requests; dual-stack listeners still avoid foreign IPv4 SO_REUSEADDR overlap on macOS.

Verified real IPv4/IPv6 Node sockets and deterministic controlled overlap; previous IPv6-only helper fails ECONNREFUSED on IPv4. Preserve HTTP35/71 assertions and NodeHTTP6/10 assertions. Full Deno/Node/browser suites pass on Deno 2.9.1 and actual floor 2.3.3 (740/740, 740/740, 435/435 each); repeated HTTP suites, checks and asset builds pass on both.
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