Repository navigation
Conversation
… auth failures
kin-openapi reads the full request body (io.ReadAll) before calling any auth
function. When that read fails - the client dropped the connection, or the
server read deadline fired while the goroutine was queued under high
concurrency - kin-openapi returns a RequestError{Reason:"reading failed"}
wrapping a net.Error, and that is carried inside the SecurityRequirementsError
because the body is read before auth runs.
On current main such a network failure flows through ProcessSecurityErrors and
is reported as a SecurityRequirementsError: logged WARN, counted as a 400/401
auth error in metrics, and marked as an error on the OTel span. All three are
misleading - nothing was wrong with the caller credentials; the connection
just went away.
Detect this case in MultiErrorHandler (new clientDisconnectReason helper): a
RequestError{reading failed} whose cause is a net.Error is tagged with
clientDisconnectPrefix instead of going to ProcessSecurityErrors. ErrorHandler
then records it as an informational span event (not an error) and returns 499
Client Closed Request, skipping c.Errors so it never looks like an auth
failure. A reading failure with a non-network cause, and genuine auth errors,
are untouched.
Rebased onto current main at the maintainers invitation on e2b-dev#3414, adapted to
the refactored error helper (processCustomErrors -> sharedauth.
ProcessSecurityErrors). Adds tests for the disconnect case as requested:
classification in MultiErrorHandler, the 499/no-c.Errors behaviour in
ErrorHandler, and an end-to-end pass through both stages.
Closes e2b-dev#3413. Supersedes e2b-dev#3414.
AdaAibaby
requested review from
ValentaTomas,
dobrac and
jakubno
as code owners
October 22, 2026 06:37
This branch has not been deployed
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.
Rebased follow-up to #3414, which @ryan-sana closed with: "A rebased PR on current main, with a test for the disconnect case, would be very welcome." This is that rebase, adapted to the refactored error helper and with the requested tests.
Problem
kin-openapireads the full request body (io.ReadAll) before calling any auth function. When that read fails — the client dropped the connection, or the server read deadline fired while the goroutine was queued under high concurrency — kin-openapi returns aRequestError{Reason:"reading failed"}wrapping anet.Error, carried inside theSecurityRequirementsError(because the body is read before auth runs).On current
mainthat network failure flows throughsharedauth.ProcessSecurityErrorsand is reported as aSecurityRequirementsError:WARN,All three are misleading — nothing was wrong with the caller's credentials; the connection just went away.
Fix
clientDisconnectReasonhelper: aRequestError{reading failed}whose cause is anet.Erroris detected inMultiErrorHandlerand tagged withclientDisconnectPrefixinstead of going toProcessSecurityErrors.ErrorHandlerrecognises the prefix, records an informational span event (telemetry.ReportEvent, not an error), returns 499 Client Closed Request, and skipsc.Errors— so it never looks like an auth failure in logs or metrics.Adapted to current main
#3414 edited
processCustomErrorsinerror.go; that was refactored intosharedauth.ProcessSecurityErrors(commit f83a684). This PR hooks the classification intoMultiErrorHandler'sSecurityRequirementsErrorcase instead, keeping the auth package unchanged.Tests (as requested)
TestMultiErrorHandlerClassifiesClientDisconnect— anet.Errorbody-read failure gets the disconnect prefix; a non-network read failure and a real missing-credential error do not.TestErrorHandlerClientDisconnectReturns499— the prefix yields 499, no response body, and nothing onc.Errors.TestMultiToErrorHandlerClientDisconnectEndToEnd— both stages together: network failure → 499, non-network read failure → auth 401.go test ./packages/api/internal/utils/passes;go build ./...andgo vetare clean.Closes #3413. Supersedes #3414.