fix: add context.Canceled checks to get-details and get-versions handlers#1345
Conversation
The inline context.Canceled checks in get-server-details and get-server-versions handlers pushed RegisterServersEndpoints cyclomatic complexity to 24 (max 20). Extract a shared RegistryError helper that handles context.Canceled, logging, and 500 responses, reducing complexity back under the limit. Also adds context.Canceled checks to both handlers (matching the pattern already used in ListServersError for the list handler).
2251a47 to
f0ce5a8
Compare
|
Hi! This PR adds This has been open for 5 days — let me know if there's anything you'd like me to adjust. |
|
Hi — just a gentle ping. CI is green (Build/Lint + Tests passing). This extends the #1335 cancellation-check pattern to and handlers — consistent 499 responses instead of noisy 500s on client disconnect. Happy to iterate if needed. |
|
Hi — gentle ping. CI is green (Build/Lint + Tests passing). Applies the same context.Canceled pattern from #1335 to the two remaining GET handlers, so all endpoints consistently return 499 on client disconnect. Happy to adjust. |
|
Hi — gentle ping. CI is green (Build/Lint + Tests passing). This applies the same context.Canceled check from #1335 to get-server-details and get-server-versions handlers — consistent 499 responses instead of noisy 500s on client disconnect. Happy to adjust if the approach needs tweaking. |
Summary
#1335 fixed the list-servers endpoint to return 499 instead of 500 when the client disconnects mid-request. But the get-server-details and get-server-versions handlers still use raw
huma.Error500InternalServerErrorwithout checking forcontext.Canceled.This PR applies the same cancellation check pattern to both remaining GET handlers, so all server endpoints consistently return 499 on client disconnect instead of logging a noisy 500 and triggering
superfluous response.WriteHeaderwarnings.Changes
internal/api/handlers/v0/servers.go: Addedcontext.Canceledcheck before logging and returning 500 in get-server-details (line ~188) and get-server-versions (line ~218)ListServersErrorinlist_errors.go(already tested)Why this matters
Without this fix, clients that disconnect during get-details or get-versions requests still produce:
superfluous response.WriteHeaderwarnings (huma tries to write to a closed socket)The fix short-circuits before the error log and 500 response, returning 499 instead.
Test plan
go test ./internal/api/handlers/v0/...)curl --max-time 0.05 http://localhost:8080/v0/servers/<name>/versions/latestno longer logs error-level cancellation