Skip to content

fix(hub): a hub that is still starting is no longer taken for another user's program - #228

Merged
7schmiede merged 1 commit into
mainfrom
fix/hub-binds-when-ready
Oct 23, 2026
Merged

7schmiede merged 1 commit into
mainfrom
fix/hub-binds-when-ready

Conversation

@7schmiede

Copy link
Copy Markdown
Member

the_token_goes_only_to_this_users_hub failed locally on a loaded Windows machine (on main too). The cause is a real bug, not only a flaky test.

Cause

serve() bound the hub's port before its setup. Part of that setup is watch_engine, whose first engine::status("docker") runs docker version synchronously, with a 5 s timeout. While it runs, the OS accepts connections on the port, but nothing answers them. The CLI's who_answers waits 3 s for /hub/ping and then reports Listener::Foreign:

  • devstack hub status: "port … answers, but not as a devstack hub of this user"
  • ensure_running() (devstack ui, open, pool shared, …): fails at once with the same message, if the hub was started by someone else (autostart at logon, while Docker Desktop is still starting, say)

The test waits only for a TCP connect, then runs hub status, so it hit the same gap whenever docker version was slow.

Fix

The hub binds its port and writes hub.json after its setup, just before it serves: what accepts a connection answers it. The state lock and the token still come before the bind, so the legacy reading in who_answers ("a hub takes the lock before it binds the port") stays true.

Tests

  • New a_hub_answers_once_its_port_takes_connections (unix only: a docker on PATH that takes 4 s; on Windows Command::new("docker") looks only for docker.exe).
  • Checked by hand on Windows with a docker.exe that sleeps 4 s:
    • before (main): the port accepts at 533 ms → hub status: "port … answers, but not as a devstack hub of this user"
    • after: the port accepts at 4161 ms → "hub running"
  • cargo test -p devstack --test hub: 14/14 on Windows; fmt, clippy clean.

🤖 Generated with Claude Code

… user's program

The hub bound its port before its setup, of which a first `docker
version` alone may take 5 s (its timeout) on a busy machine or while
Docker Desktop starts. The port took connections it did not answer; the
CLI, which waits 3 s for `/hub/ping`, took the hub for another user's
program: `devstack hub status`, `devstack ui`, `devstack open` said
"port ... answers, but not as a devstack hub of this user" and gave up.
Seen as `the_token_goes_only_to_this_users_hub` failing on a loaded
Windows machine.

The hub now binds its port, and writes hub.json, after its setup: what
accepts a connection answers it. The state lock and the token still come
first, so `who_answers`' reading of an older hub stays true.

A test (unix: a `docker` on PATH that takes 4 s) starts a hub and asks
`hub status` as soon as the port takes connections.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@7schmiede
7schmiede merged commit c13a114 into main Oct 23, 2026
11 checks passed
@7schmiede
7schmiede deleted the fix/hub-binds-when-ready branch October 23, 2026 09:02
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