fix(handlers): return 499 on client cancel for get-server endpoints - #1401
fix(handlers): return 499 on client cancel for get-server endpoints#1401piyushbag wants to merge 2 commits into
Conversation
Extend the ListServersError pattern from modelcontextprotocol#1335 to get-server-version and get-server-versions so benign client disconnects no longer log as 500s or trigger huma superfluous WriteHeader warnings. Fixes modelcontextprotocol#1323
Satisfy revive error-return: multiple return values must end with error.
c4c19a8 to
7fe3483
Compare
|
Rebased onto current Local: package builds. |
|
Went through this one with the tests actually running plus a few probes against the head commit ( Things I checked that came out clean:
One thing worth flagging: The 499 body serializes the underlying error, including anything sensitive in it. {"status":499,"detail":"Client closed request",
"errors":[{"message":"error iterating rows: dsn=postgres://user:pw@internal-host/db: context canceled"}]}That's from a real HTTP round trip, not a unit test. The 500 path four lines up deliberately does the opposite, with a comment saying why: // Do not pass err here: huma serializes extra error args into the responseand To be fair about severity: I don't think it's reachable with a live connection today. return true, huma.NewError(499, "Client closed request")Two smaller things:
One piece of context in case it affects how you weigh this: For completeness on test results: Nice, tightly scoped change overall — the deliberate |
Summary
ListServersErrorpattern to the get-server-version and get-server-versions handlersWriteHeaderclientClosedRequestand add unit tests for the new helpersFixes #1323 (handler-side scope; CDN/RPS follow-up tracked separately on the issue)
Problem
#1335 fixed cancellation handling for
GET /v0/serversonly. rdimitrov noted that PR only partially addressed #1323. The get-server-version and get-server-versions handlers still logged benign cancellations at error level and returned 500, which can trigger humasuperfluous response.WriteHeaderwarnings.Test plan
go test ./internal/api/handlers/v0/... -run 'ListServersError|GetServerDetailsError|GetServerVersionsError'go test -race ./internal/api/handlers/v0/... -run 'ListServersError|GetServerDetailsError|GetServerVersionsError'go vet ./internal/api/handlers/v0/...