Skip to content

Conversation

@Fedosin
Copy link
Contributor

@Fedosin Fedosin commented Nov 5, 2025

Fixes #15850

Proposed Changes

Add synchronization for HTTP header map access during request timeouts. When a timeout occurs, capture a snapshot of headers to prevent concurrent modification by the inner handler after the timeout handler returns.

Release Note

NONE

@knative-prow knative-prow bot requested a review from linkvt November 5, 2025 13:16
@knative-prow knative-prow bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 5, 2025
@knative-prow knative-prow bot requested a review from skonto November 5, 2025 13:16
@knative-prow
Copy link

knative-prow bot commented Nov 5, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Fedosin
Once this PR has been reviewed and has the lgtm label, please assign dsimansk for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@codecov
Copy link

codecov bot commented Nov 5, 2025

Codecov Report

❌ Patch coverage is 76.92308% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.10%. Comparing base (41fafd1) to head (a2e2dde).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
pkg/http/handler/timeout.go 76.92% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16222      +/-   ##
==========================================
+ Coverage   80.04%   80.10%   +0.06%     
==========================================
  Files         214      214              
  Lines       13313    13325      +12     
==========================================
+ Hits        10656    10674      +18     
+ Misses       2296     2292       -4     
+ Partials      361      359       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Add synchronization for HTTP header map access during request timeouts.
When a timeout occurs, capture a snapshot of headers to prevent concurrent
modification by the inner handler after the timeout handler returns.

Fixes knative#15850
})
}

func TestTimeoutHandlerConcurrentHeaderAccess(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure that this test would actually catch verify the problem?
I tried running it locally without the fix 1000 times but the test didn't fail.

Comment on lines +302 to 309
// Capture a snapshot of headers before marking as timed out
// to prevent concurrent access to the underlying header map
tw.headers = make(http.Header)
for k, v := range tw.w.Header() {
tw.headers[k] = slices.Clone(v)
}

tw.w.WriteHeader(http.StatusGatewayTimeout)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not 100% sure if I understood the timeoutHandler/Writer stuff correctly but wouldn't we still see a concurrent access to the map here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Activator sometimes crashing when requests time out

2 participants