Skip to content

Fix the dashboard speed test (upload leg never completed) and surface HTTP errors - #1

Merged
MonkeyIsNull merged 1 commit into
mainfrom
fix-speedtest-upload
Oct 8, 2026
Merged

MonkeyIsNull merged 1 commit into
mainfrom
fix-speedtest-upload

Conversation

@MonkeyIsNull

Copy link
Copy Markdown
Owner

Root cause — the button never once succeeded

RUN SPEED TEST always failed on the upload leg. measureStream (speed.go) launched its worker goroutines but never joined them — it computed samples, called cancel(), and returned. The ok-aware upload worker streams one ~50 MB POST per goroutine, which can't finish inside the ~4 s reduced-load window, so it recorded no 200 / non-200 / transport error before measureStream returned. onDemandSpeed then read the empty upload tally -> ok:false, "upload: no data received". Download always worked (it records a 200 on the first response), which is exactly why only the upload leg failed.

Before: {download_mbps:0, upload_mbps:0, ok:false, error:"upload: no data received..."}
After: {download_mbps:29.16, upload_mbps:30.74, latency_ms:24.93, ok:true}

Fix

  • speed.go measureStream: wrap workers in a sync.WaitGroup and wg.Wait() after cancel() so a tally-recording worker has finished before the caller reads the tally (also closes a goroutine leak). The --speed CLI path is behavior-identical.
  • speedbutton.go: a window-end cancellation (ctx.Err() != nil) is no longer recorded as a transport error (it's normal termination). New speedLegErr treats a leg that pushed real bytes with no server rejection as a success even with zero recorded 200s (fixes upload); a server rejection still wins and is surfaced.

Error visibility (incl. the requested 429 handling)

tallyErr now distinguishes HTTP status failures and flows them into the panel error:

  • 429 -> "rate-limited by server (HTTP 429) — try again in a bit"
  • 503 + Retry-After -> "server busy / rate-limited (HTTP 503) — try again in a bit"
  • other 5xx -> "server error (HTTP N)"; else "server returned HTTP N".

The client JS already matched the wire shape (download_mbps/upload_mbps/latency_ms/jitter_ms/target/ok/error), so no JS change was needed — the contract was never the bug.

SSRF protections — intact (verified live)

missing header -> 403, GET -> 405, custom->127.0.0.1 -> 400, custom->169.254.169.254 -> 400, non-loopback Origin -> 403. validateSpeedTarget allowlist + dial-time guardedDialContext re-check untouched — only accept-rows added, no block relaxed.

Tests

TestMeasureStreamJoinsWorkers (root-cause regression), TestSpeedLegErr, TestDefaultConfigSpeedTargetsValidate, extended TestValidateSpeedTarget (default Cloudflare targets accepted) and TestTallyErrClassification (429 / 503+Retry-After / bare 503 / 502). go build/vet/test green; -race clean; dashboard guard tests pass.

… HTTP errors

The RUN SPEED TEST button always failed on the upload leg. measureStream launched its worker goroutines but never joined them, so onDemandSpeed read the upload tally while it was still empty and reported 'upload: no data received'. The upload worker streams one 50MB POST per goroutine, which can't finish inside the ~4s reduced-load window, so it recorded no 200 before the premature read; download worked because it records a 200 on the first response -- which is why only the upload leg failed and the button never once succeeded.

Fix: measureStream now wraps its workers in a sync.WaitGroup and waits after cancel (also closing a goroutine leak). A window-end cancellation is no longer counted as a transport error. New speedLegErr treats a leg that pushed real bytes with no server rejection as a success even with zero recorded 200s (fixes upload), while a server rejection still wins and is surfaced.

Error visibility: tallyErr now distinguishes HTTP status failures -- 429 -> 'rate-limited by server (HTTP 429) — try again in a bit', 503 with Retry-After -> similar, other 5xx -> 'server error (HTTP N)', else 'server returned HTTP N' -- which flow into the panel error. The client JS already matched the wire shape, so no JS change was needed. SSRF protections are unchanged (validateSpeedTarget allowlist + dial-time guardedDialContext re-check verified intact). Tests: TestMeasureStreamJoinsWorkers (root-cause regression), TestSpeedLegErr, TestDefaultConfigSpeedTargetsValidate, extended TestValidateSpeedTarget and TestTallyErrClassification (429/503/502). Verified end to end: before download/upload 0 ok:false; after download 29.16 / upload 30.74 Mbps ok:true.
@MonkeyIsNull
MonkeyIsNull merged commit e937db6 into main Oct 8, 2026
1 check passed
@MonkeyIsNull
MonkeyIsNull deleted the fix-speedtest-upload branch October 8, 2026 21:03
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