OCPBUGS-99052: recover from reverse proxy panic on browser disconnect#16776
OCPBUGS-99052: recover from reverse proxy panic on browser disconnect#16776logonoff wants to merge 1 commit into
Conversation
|
Pipeline controller notification For optional jobs, comment This repository is configured in: LGTM mode |
|
@logonoff: This pull request references Jira Issue OCPBUGS-99052, which is valid. The bug has been moved to the POST state. 3 validation(s) were run on this bug
The bug has been updated to refer to the pull request using the external bug tracker. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
|
/verified by TestK8sViaProxy_RecoversAbortPanic |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: logonoff The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
@logonoff: The label(s) DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
@logonoff: This PR has been marked as verified by DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
|
/label acknowledge-critical-fixes-only |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: openshift/coderabbit/.coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
Walkthrough
ChangesHTTP handler abort recovery
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 14 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (14 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
@logonoff: This pull request references Jira Issue OCPBUGS-99052, which is valid. 3 validation(s) were run on this bug
DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pkg/server/api_discovery_test.go (1)
316-332: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winCover the unexpected-panic branch.
This test verifies
http.ErrAbortHandler, but not the promised behavior that unrelated panics are re-raised. Add a second case that panics with another value and asserts thatk8sViaProxypropagates it; otherwise a future recovery change could silently swallow real bugs while this test still passes.This preserves the PR’s stated contract that unexpected panics are re-raised.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pkg/server/api_discovery_test.go` around lines 316 - 332, Extend TestK8sViaProxy_RecoversAbortPanic with a separate case using a panic value other than http.ErrAbortHandler, and assert that k8sViaProxy re-panics with that same value. Keep the existing aborted-request error assertions unchanged and ensure the test fails if unexpected panics are swallowed.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@pkg/server/api_discovery_test.go`:
- Around line 316-332: Extend TestK8sViaProxy_RecoversAbortPanic with a separate
case using a panic value other than http.ErrAbortHandler, and assert that
k8sViaProxy re-panics with that same value. Keep the existing aborted-request
error assertions unchanged and ensure the test fails if unexpected panics are
swallowed.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 8f3f44f7-8813-4f33-bc30-ddf14488e5cf
📒 Files selected for processing (2)
pkg/server/api_discovery.gopkg/server/api_discovery_test.go
|
/retest |
|
Scheduling tests matching the |
The API discovery handler uses httptest.NewRecorder to make in-process requests through the k8s reverse proxy. When a browser disconnects mid-request (e.g. page refresh), httputil.ReverseProxy panics with http.ErrAbortHandler during response body copy. Unlike a real HTTP server, the recorder has no server to catch this panic, crashing the goroutine. Add a defer/recover in k8sViaProxy that catches http.ErrAbortHandler and converts it to an error. Unexpected panics are re-raised. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
16ccd09 to
38a8d7c
Compare
|
/pipeline required |
|
@logonoff: This PR has been marked as verified by DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
|
@logonoff: This pull request references Jira Issue OCPBUGS-99052, which is valid. 3 validation(s) were run on this bug
DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
Analysis / Root cause:
The API discovery endpoint (
/api/api-discovery) useshttptest.NewRecorderto make in-process requests through the k8s reverse proxy. When a browser disconnects mid-request (e.g. page refresh or navigation), httputil.ReverseProxypanics withhttp.ErrAbortHandler` during response body copy. Unlike a real HTTP server, the recorder has no server to catch this panic, crashing the goroutine.Reproducible by rapidly refreshing the browser directly on the api-discovery backend route on HTTP/1.1.
Solution description:
Add a
defer/recoverink8sViaProxythat catcheshttp.ErrAbortHandlerspecifically and converts it to an error return. Unexpected panics are re-raised. The first parameter type is widened from*proxy.Proxytohttp.Handlerto allow injecting a mock handler in tests.Screenshots / screen recording:
N/A — backend-only fix, no UI changes.
Test setup:
No special setup required. Run
go test ./pkg/server/ -run TestK8sViaProxy -v.Test cases:
TestK8sViaProxy_RecoversAbortPanic: Injects anhttp.HandlerFuncthat panics withhttp.ErrAbortHandler(reproducing whathttputil.ReverseProxydoes on a broken connection) and verifiesk8sViaProxyreturns an error instead of panicking. Deterministically fails without the fix (panic: net/http: abort Handler).Browser conformance:
Additional info:
Stack trace from the crash:
Depends on CONSOLE-5426 (#16769).
Summary by CodeRabbit