Skip to content

Test flake: hardcoded kubo API ports in macOS ephemeral range cause intermittent 'address already in use' #87

@Rinse12

Description

@Rinse12

Problem

macOS CI intermittently fails (e.g. run 27199400016) with:

Daemon failed to start: Error: serveHTTPApi: manet.Listen(/ip4/0.0.0.0/tcp/50599) failed:
  listen tcp4 0.0.0.0:50599: bind: address already in use

Root cause

Every kubo API port hardcoded in the test suite (50039, 50049, 50079, 50089, 50099, 50121, 50129, 50139, 50209, 50299, 50309, 50399, 50499, 50599, …) falls inside macOS's ephemeral port range (49152–65535). With fileParallelism: true, the macOS kernel can transiently assign one of those ports as the source port for an outbound fetch() from a concurrently running test file, so kubo's bind on that port intermittently fails. (Swarm ports were already fixed via preInitKuboWithEphemeralSwarm/tcp/0; API/gateway/RPC were not.)

Proven fix already in-repo

test/kubo/kuboRpcGateway.integration.test.ts already does the right thing — allocate a free port via net bind-to-:0, then retry kubo startup on /already in use/i with fresh ports. It is not flaky.

Plan

  • Add shared test helpers: allocateFreePort(), allocateKuboEndpoints(), startPkcDaemonWithDynamicPorts() (retry on bind race) in test/helpers/daemon-helpers.ts.
  • Make preInitKuboWithEphemeralSwarm idempotent so retries can reuse a seeded dataPath.
  • Convert the static-port daemon/kubo test files to dynamic ports + retry.
  • Add a focused regression test for the helper (port allocation + retry-on-EADDRINUSE).
  • Build + full npm run test:cli green locally.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions