Skip to content

Require a response, not just a connect, to call an app running - #11

Merged
maxsoldev merged 2 commits into
mainfrom
fix-apprunning-always-true
Oct 9, 2026
Merged

maxsoldev merged 2 commits into
mainfrom
fix-apprunning-always-true

Conversation

@maxsoldev

Copy link
Copy Markdown
Collaborator

Fixes #8.

The problem

appRunning was true for every project with a port assigned. The probe was a bare TCP connect, but appx publishes the whole app port range from the outer container, so one docker-proxy process accepts on every port in the range regardless of what is behind it — it completes the handshake and only resets once the client writes.

Verified against a real docker-proxy (not a fake):

$ docker run -d -p 127.0.0.1:10500-10502:10500-10502 python:3-alpine \
    sh -c 'cd /www && python3 -m http.server 10500'   # only 10500 serves

$ python3 -c "import socket; socket.create_connection(('127.0.0.1',10502),2); print('connect OK')"
connect OK      # <- the old probe's entire test, on a port with nothing behind it

The fix

portServing writes a minimal HEAD request and waits for a reply:

Observed Verdict
Response bytes up
Read timeout (accepted, hasn't answered) up
RST or EOF before any response down
Dial failure down

A timeout counting as up is deliberate: a transiently slow app should not flicker to "not running". The only false-negative shape left is a server that closes without replying at all, which no HTTP server does. Probing with HTTP is safe because appx only ever reverse-proxies HTTP to these ports (router.go dials http://127.0.0.1:<port>), so every app on them is an HTTP server by construction.

The devPort gap

The issue's secondary point: only AssignedPort was probed, so a project whose DEV server was the running one was indistinguishable from one running nothing. Check now returns Health{App, Dev} per project and the API reports devRunning alongside appRunning. The frontend follows the distinction it already implied:

  • preview iframe (targets the -dev subdomain) → gated on devRunning (was appRunning)
  • "Open App" (targets PROD) → appRunning
  • dashboard card → RUNNING / DEV RUNNING / NOT STARTED

Cost

maxConcurrentDials 20 → 64, since a sweep is now two probes per project. No result cache — the issue suggested considering one, but a 30-project sweep with every port probed measures ~10ms, so there is nothing to amortise. Easy to add later if the range fills up.

Testing

Unit tests reproduce the docker-proxy shape in-process (acceptThenClose, both graceful FIN and RST):

  • TestHealthChecker_PublishedPortWithNothingBehindIt — the regression test
  • TestHealthChecker_RespondingServer / _SilentListenerIsUp — both up-verdicts
  • TestHealthChecker_DevPortProbedSeparately — DEV up, PROD empty
  • TestGetProject_ReportsDevAndProdSeparately — API shape

Plus dockerproxy_manual_test.go, an env-gated manual test against a real container (skipped by default; the setup command is in its doc comment). In-process fakes can only approximate docker-proxy, so this pins the real thing:

$ APPX_PROBE_SERVING_PORT=10500 APPX_PROBE_EMPTY_PORT=10502 go test ./internal/project -run DockerProxy -v
    connect-only probe on 10500: SUCCEEDED (old behaviour: reported running)
    portServing(10500) = true (correct)
    connect-only probe on 10502: SUCCEEDED (old behaviour: reported running)
    portServing(10502) = false (correct)
--- PASS

Happy to drop that file if you'd rather not carry a skipped test.

End-to-end through the real binary, with a project pointed at the published-but-empty port 10502 and a dev server on 10600:

$ curl -s -b cj http://127.0.0.1.sslip.io:8097/api/projects
devonly    prod=10502 appRunning=False dev=10600 devRunning=True
nothing    prod=10501 appRunning=False dev=10800 devRunning=False

Both rows reported appRunning=true before this change. Driving the UI with Playwright: the dashboard shows devonly as DEV RUNNING and nothing as NOT STARTED; the project page shows the DEV badge, keeps the preview pane (iframe renders the dev app through the -dev subdomain proxy), and correctly omits the "Open App" link that previously pointed at a PROD port with nothing behind it.

task build, task test, task lint pass.

🤖 Generated with Claude Code

appRunning was true for every project with a port assigned. The probe was a
bare TCP connect to 127.0.0.1:<port>, but appx publishes the whole app port
range (10000-10199) from the outer container, so one docker-proxy process
accepts on every port in the range whether or not anything is behind it. It
completes the handshake and only resets once the client writes, so the probe
could never return false.

portServing now writes a minimal HEAD request and waits for a reply. Only a
reset or an EOF *before any response* counts as down; a read timeout counts
as up, because a listener that accepted the request and has not answered yet
is still a listener. That bias is deliberate — a transiently slow app should
not flicker to "not running". Probing with HTTP is safe because appx only
ever reverse-proxies HTTP to these ports, so every app on them is an HTTP
server by construction.

Also closes the devPort gap from the same issue: only AssignedPort was
probed, so a project whose DEV server was the running one looked identical
to one running nothing. Check now returns a Health{App, Dev} per project and
the API reports devRunning alongside appRunning. The frontend follows the
distinction it already implied — the preview iframe (which targets the DEV
subdomain) is gated on devRunning, "Open App" (PROD) on appRunning, and the
dashboard card distinguishes DEV RUNNING from RUNNING.

maxConcurrentDials goes 20 -> 64 since a sweep now costs two probes per
project. No result cache: a 30-project sweep with every port probed measures
~10ms, so there is nothing to amortise yet.

Fixes #8

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@maxsoldev
maxsoldev merged commit cc4c1eb into main Oct 9, 2026
1 check passed
@maxsoldev
maxsoldev deleted the fix-apprunning-always-true branch October 9, 2026 09:49
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.

appRunning is always true in container mode: the health probe connects to a port Docker publishes for the entire range

1 participant