Skip to content

fix: wait for hijacked connections to close during drain#16625

Open
immanuwell wants to merge 1 commit into
knative:mainfrom
immanuwell:fix/hijack-tracker-drain
Open

fix: wait for hijacked connections to close during drain#16625
immanuwell wants to merge 1 commit into
knative:mainfrom
immanuwell:fix/hijack-tracker-drain

Conversation

@immanuwell
Copy link
Copy Markdown
Contributor

Fixes #

Proposed Changes

  • keep hijacked conns counted til the wrapped net.Conn closes
  • preserve Flush() and Unwrap() on the tracker wrapper
  • add regression tests for a real Hijack() path, not just a blocked handler

Repro:

  1. Open a websocket to a Knative Service.
  2. Send TERM to the queue-proxy while that socket is still open.
  3. Before this patch, the handler can return right after Hijack(), so HijackedDrainer.Drain() may see zero inflight too early and exit. The websocket gets cut off early, which is kinda rough.
  4. With this patch, drain waits for the hijacked conn to close, or hits the existing 60s cap.

Related: follow-up to #16362.

Release Note

queue-proxy now waits for hijacked connections to close before finishing drain

@knative-prow knative-prow Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels May 29, 2026
@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented May 29, 2026

Hi @immanuwell. Thanks for your PR.

I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

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.

@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented May 29, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

Details 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

@knative-prow knative-prow Bot requested review from dprotaso and skonto May 29, 2026 14:50
@codecov
Copy link
Copy Markdown

codecov Bot commented May 29, 2026

Codecov Report

❌ Patch coverage is 90.90909% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.38%. Comparing base (f9dd97e) to head (a95113d).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
pkg/http/handler/hijack.go 90.90% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16625      +/-   ##
==========================================
+ Coverage   80.28%   80.38%   +0.09%     
==========================================
  Files         217      217              
  Lines       13568    13589      +21     
==========================================
+ Hits        10893    10923      +30     
+ Misses       2312     2303       -9     
  Partials      363      363              

☔ 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.

}

func (w *hijackTrackerResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
conn, rw, err := websocket.HijackIfPossible(w.ResponseWriter)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't know if we want to introduce websocket hijacking into the queue proxy. The idea before was to track this transparently so we're not pulling in extra dependencies etc.

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

Labels

needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. 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.

2 participants