Skip to content

workerd CI scenarios can fail when wrangler's port is taken before it binds #54

Closed

Description

@okomarov

The Cloudflare workerd job failed once on PR #53 (run 38468041845) in the end-tls scenario, before any library code ran:

Fatal uncaught kj::Exception: ... ::bind(...): Address already in use; toString() = 127.0.0.1:40039
Address already in use (127.0.0.1:40039). Please check that you are not already running a server on this address or specify a different port with --port.

The rerun passed. The change under test does not touch the workerd scenarios.

Cause

tests-startup/workerd-run.mjs chooses ports with freePort() (lines 36–41): it listens on port 0, reads the port, closes the listener, and later passes the number to wrangler dev --port. Anything can take the port in between, including processes from the previous scenario that are still shutting down. Lines 67–68 also choose the main and inspector ports with two separate calls, so both can get the same number.

Options

  • Retry a scenario once when wrangler's output contains Address already in use, with fresh ports.
  • Choose both ports while holding the first listener open, so they cannot be equal, and wait for the previous scenario's process group to exit before starting the next.
  • Let wrangler choose the port and read it from its output, if wrangler 4 reports it reliably.

A retry is the smallest change and also covers ports taken by unrelated processes.

Activity

  1. added
    area: runtimes
    area: project
    bug
    on Oct 16, 2026
  2. moved this to Later in Roadmapon Oct 16, 2026
  3. moved this from Later to In progress in Roadmapon Oct 18, 2026
  4. okomarov commented on Oct 18, 2026

    @okomarov
    Author

    PR #150 chose both ports while holding the first listener open and retried once on Address already in use. PR #151 goes further: the runner now uses Wrangler's createTestHarness() (Cloudflare's recommended integration-test API), one harness per build and compatibility date, reset before each scenario. There are no wrangler dev processes or chosen ports left, so this race cannot recur. Closes when #151 lands.

  5. moved this from In progress to Shipped in Roadmapon Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: projectarea: runtimesbug

    Type

    No type

    Projects

    • Status
      Shipped

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions