Skip to content

Reserve automatic HTTP ports until server startup - #63246

Open
domenic wants to merge 1 commit into
codex/stash-process-contextfrom
codex/http-port-reservations
Open

domenic wants to merge 1 commit into
codex/stash-process-contextfrom
codex/http-port-reservations

Conversation

@domenic

@domenic domenic commented Oct 4, 2026 •

Copy link
Copy Markdown
Member

Keep automatically allocated HTTP-family ports bound through server startup, following up on port-collision failures in jsdom's use of wpt serve.

Stacked on #63245 using GitHub's stacked pull requests feature.


This is part of a series of PRs to try to fix port-allocation races that jsdom has encountered while using wpt serve. I asked GPT-6 Astra Extra High to extract them into small, reviewable fixes, but I'm still not much of an expert in this code, so please review carefully.

This one is the complicated one, certainly.

wpt serve and wptrunner choose automatic ports by binding temporary sockets and closing them before starting the servers. Another listener can claim an HTTP port between configuration and startup, causing the server process to fail with EADDRINUSE.

Keep automatically allocated HTTP, HTTPS, and HTTP/2 sockets bound until their server processes adopt them. Allocate on the address the server will use, exclude explicitly configured ports, and transfer raw sockets so TLS setup still happens in the server process. Apply the same handoff to the temporary HTTP server used to check subdomains.

Reservations remain separate from the serializable configuration. The configuration builder closes unclaimed sockets on exit or configuration failure; startup closes parent copies after transfer and releases reservations for disabled servers. Forked children close reservations belonging to other servers so those ports do not remain occupied by unrelated processes.

Do not listen on reserved sockets until the HTTP server initializes: wptrunner uses a successful TCP connection as a readiness check. Avoid SO_REUSEADDR while reserving a port, since it can allow competing binds before listen; use SO_EXCLUSIVEADDRUSE on Windows.

Co-authored-by: codex <codex@openai.com>
@wpt-pr-bot wpt-pr-bot added infra serve wptrunner The automated test runner, commonly called through ./wpt run wptserve labels Oct 4, 2026
@domenic
domenic added this pull request to stack #63247 October 4, 2026 09:06

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

infra mozilla:gecko-blocked serve wptrunner The automated test runner, commonly called through ./wpt run wptserve

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants