oliver-zehentleitner / maity

web e2e harness: MailCatcher can bind the hub's port (free_port race) — flaky mail-factor step

Sign in to report

tsk-vfdn98vwa0ym Done An agent

Found by Grok jc4h in A2188 (PR #2131, run 45117122878, job 137502570723; the re-run 137518897184 passed on the same head).

Cause:

  • web/tools/e2e.py:3213 free_port picks a port and closes it again before the hub binds it.
  • The SMTP MailCatcher (:502) then binds port 0, and the OS can hand it the hub's port.
  • The hub's health URL is then answered by the MailCatcher. The e2e fails in "mail factor hub ...", and the fake SMTP logs ConnectionResetError.

Fix: remove the race. Options:

  • start_hub keeps its socket open, or passes it to the hub;
  • or MailCatcher binds first, and free_port excludes its port;
  • or both get their ports from one allocator that holds them.

Pick the smallest change that makes a collision impossible, not just less likely.

Proof: a test or a forced run showing the collision on the old harness (e.g. monkeypatch MailCatcher to take the port free_port returned), and that it cannot happen on the new one. web-e2e green.

Scope: web/tools/e2e.py only, plus a changelog fragment if needed. No hub or web code.

Notes

  1. Maity Test Team · Nov 23, 2026, 09:27 UTC

    Tester check on main 18a070972 (PR #2133 merged) — pass.

    • HTTP_PROXY=http://127.0.0.1:9 http_proxy=http://127.0.0.1:9 python3 web/tools/test_e2e_harness.py → all ok, exit 0 (including the guard cases for nested def, lambda, default argument, and positional/indirect avoid).
    • Forced collision, headless (playwright stubbed only so that the module imports): I started a real MailCatcher() and patched socket.getsockname so that the OS's first pick returns the catcher's port. free_port(avoid={catcher.port}) → catcher 39239, picked 52975 after 2 tries, so no collision. With the same forced pick and no avoid (the old call), free_port() returns 39239, the catcher's port, which reproduces the old race.
    • The three mail rounds in web/tools/e2e.py (lines 2806, 3224, 3387) call free_port(avoid={catcher.port}) after the catcher has bound.
    • Not run here: a full web-e2e (no playwright/browser stack in this headless check).