Skip to content

fix(api): classify client-disconnect body-read errors separately from auth failures - #3414

Open
AdaAibaby wants to merge 1 commit into
e2b-dev:mainfrom
AdaAibaby:fix/api-classify-client-disconnect-errors
Open

fix(api): classify client-disconnect body-read errors separately from auth failures#3414
AdaAibaby wants to merge 1 commit into
e2b-dev:mainfrom
AdaAibaby:fix/api-classify-client-disconnect-errors

Conversation

@AdaAibaby

@AdaAibaby AdaAibaby commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Closes #3413

Summary

  • Add clientDisconnectPrefix constant to packages/api/internal/utils/error.go
  • In processCustomErrors: detect RequestError{Reason:"reading failed"} with an underlying net.Error and return it under the new prefix — preventing it from being reported as an auth failure
  • In ErrorHandler: handle the new prefix before the telemetry/c.Error path — record a span event via telemetry.ReportEvent (informational, not error), respond 499, skip c.Errors

Why

kin-openapi reads the full request body (io.ReadAll) before calling any auth function. Under high concurrency the server ReadTimeout: 10s can expire while goroutines queue, producing net.Error wrapped in SecurityRequirementsError. Without this fix those network timeouts are logged as WARN with a SecurityRequirementsError message, counted as 400 auth errors in metrics, and set OTel span error status — all misleading.

Test plan

  • Build passes: go build ./packages/api/...
  • Deploy to staging, generate high concurrency (≥ 100 simultaneous sandbox creates); confirm 499 responses appear and no SecurityRequirementsError WARN lines are emitted for client disconnects
  • Verify genuine auth failures (bad API key, expired token) still produce 401/403 with SecurityRequirementsError logged as before

/cc @jakubno @dobrac @ValentaTomas @arkamar @tvi Looking forward to your code review.

… auth failures

kin-openapi reads the entire request body (io.ReadAll) before invoking
any auth function. Under high concurrency the server ReadTimeout or the
client SDK timeout can fire during that read, producing a net.Error that
kin-openapi wraps in SecurityRequirementsError. processCustomErrors then
formats it with securityErrPrefix, ErrorHandler calls telemetry.ReportError
(OTel error status + WARN log), and the response goes out as 400 — all of
which falsely indicates an authentication failure.

Detect RequestError{Reason:"reading failed"} with an underlying net.Error
in processCustomErrors and return it under a new clientDisconnectPrefix.
ErrorHandler handles this prefix early: records a span event via
telemetry.ReportEvent (informational, not error), and responds 499 without
adding to c.Errors — so the logging middleware emits a plain WARN with the
route path rather than the misleading SecurityRequirementsError message.

This makes client-disconnect events visible and queryable in metrics (by
499 vs 400/401/403) without polluting auth-failure dashboards and alerts.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

api: client-disconnect body-read failures are misclassified as auth errors (400 WARN noise)

2 participants