fix: add context.Canceled checks to get-details and get-versions handlers#1345
Open
friendlygeorge wants to merge 1 commit into
Open
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
Author
|
Hi! This PR adds This has been open for 5 days — let me know if there's anything you'd like me to adjust. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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