Skip to content

fix(registration): probe the bind port separately from the advertised port - #42

Merged
mortenoh merged 4 commits into
mainfrom
fix/registration-probe-port
Sep 30, 2026
Merged

mortenoh merged 4 commits into
mainfrom
fix/registration-probe-port

Conversation

@mortenoh

Copy link
Copy Markdown
Contributor

Fixes CLIM-1248: a service whose advertised port (SERVICEKIT_PORT) differs from the port it binds, for example a container run with -p 18701:8000 and registering with an orchestrator on the Docker host, never passed the readiness gate and skipped registration, because the gate probed 127.0.0.1:<SERVICEKIT_PORT>.

Changes

  • The readiness gate now probes the local bind port, resolved separately from the advertised port: with_registration(local_port=...) if set (exclusively), otherwise PORT (or local_port_env), the advertised port, and 8000 are tried in turn. Existing setups where the advertised port equals the bind port keep working.
  • The probe only accepts its own app: a per-instance random token is sent in x-servicekit-readiness-token and echoed back by a small ASGI middleware installed outside auth, so another server on a candidate port (such as an orchestrator on 8000) is never mistaken for the service, and auth-protected apps still pass.
  • run_app now exports the port uvicorn binds as PORT, alongside the existing SERVICEKIT_PORT default.
  • Registration guide and example README: SERVICEKIT_PORT is the port as seen from the orchestrator (container port on a shared Docker network, published host port when the orchestrator runs on the host); documented local_port / local_port_env.

Verification

  • make lint and make test pass (513 passed, 5 skipped); new tests cover port candidates, token matching, a decoy server on a candidate port, and the CLIM-1248 scenario.
  • End to end with plain uvicorn svc:app --port 8000 and SERVICEKIT_PORT=18701: the probe finds the app on 8000 and it registers as host.docker.internal:18701. With the orchestrator itself answering /health on 8000, it is ignored.

No breaking change to the public API; the renamed helpers (_resolve_port, _wait_until_ready) are private.

@codecov

codecov Bot commented Sep 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@mortenoh

Copy link
Copy Markdown
Contributor Author

@claude review

@mortenoh
mortenoh merged commit 23c2522 into main Sep 30, 2026
8 checks passed
@mortenoh
mortenoh deleted the fix/registration-probe-port branch September 30, 2026 12:19
@mortenoh mortenoh mentioned this pull request Sep 30, 2026
mortenoh added a commit that referenced this pull request Sep 30, 2026
Bump version 2.0.2 -> 2.0.3 and refresh the lockfile. Patch release probing the local bind port for registration readiness separately from the advertised port (#42).
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