Skip to content

fix(triple): reset a client stream when its context ends - #3897

Open
AsperforMias wants to merge 1 commit into
apache:developfrom
AsperforMias:fix/triple-stream-cancel-reset
Open

AsperforMias wants to merge 1 commit into
apache:developfrom
AsperforMias:fix/triple-stream-cancel-reset

Conversation

@AsperforMias

Copy link
Copy Markdown
Contributor

Description

Fixes #3894

Go's HTTP/2 transport watches the request context only until the response headers arrive. After that, canceling the context of a Triple bidi stream sent no RST_STREAM: the goroutine writing the still-open request body was blocked on the body pipe, or the transport was waiting for flow-control credit, and nothing aborted the stream. The provider handler and its HTTP/2 stream stayed alive until the consumer closed the stream or the connection, although cancel() is the usual way to stop a stream in gRPC.

Changes

  • duplexHTTPCall watches its context. When it ends, the call releases the response, which makes the transport reset the stream, also while it waits for flow control, and fails the request body, which wakes a blocked writer on transports that do not close it. Before the response arrives the transport already watches the context, as before.
  • The watch stops when the response ends, fails or is released, so a finished call is not kept reachable through a long-lived context.
  • A Send or Receive cut off by the end of the context reports Canceled or DeadlineExceeded instead of Unknown: the closed request pipe maps to the context error, and the envelope reader and writer keep coded errors in the middle of a message as they already did for the prefix.

The problem is in v3.3.2-20260910 as well as on develop.

Verification

  • TestCancelEndsServerStream: the consumer only cancels, before the response, after the first response, and while a 16 MiB request waits for flow control because the server stopped reading. The handler must end with context.Canceled and the blocked Send must return Canceled. The last two cases fail without the fix.
  • TestEnvelopeKeepsCodedErrorMidMessage covers the codes in the middle of a message.
  • End-to-end with a Triple provider and consumer, the consumer canceling after its first response: on develop and v3.3.2-20260910 the provider handler's context ended only when the consumer process exited, 3.5 s later; with this branch it ends at the cancel and the provider sees CANCEL.

Independent of #3896; the two touch different files in protocol/triple/triple_protocol.

Checklist

  • I confirm the target branch is develop
  • I have run make fmt to format my code
  • I have run make test to run local tests
  • I have added tests that prove my fix is effective or that my feature works

Once the response headers arrive, Go's HTTP/2 transport stops watching
the request context. Canceling the context of a bidi stream after its
first response therefore sent no RST_STREAM: the provider handler and its
HTTP/2 stream stayed alive until the consumer closed the stream or the
connection, also when request data was waiting for flow control.

When the context ends, release the response, which makes the transport
reset the stream, and fail the request body. The watch stops when the
response ends, fails or is released. A Send or Receive cut off by the
end of the context now reports Canceled or DeadlineExceeded instead of
Unknown.
@sonarqubecloud

Copy link
Copy Markdown

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.77778% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.09%. Comparing base (60d1c2a) to head (386bc9a).
⚠️ Report is 1073 commits behind head on develop.

Files with missing lines Patch % Lines
...rotocol/triple/triple_protocol/duplex_http_call.go 73.91% 3 Missing and 3 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           develop    #3897       +/-   ##
============================================
+ Coverage    46.76%   61.09%   +14.32%     
============================================
  Files          295      515      +220     
  Lines        17172    42450    +25278     
============================================
+ Hits          8031    25935    +17904     
- Misses        8287    14703     +6416     
- Partials       854     1812      +958     

☔ View full report in Codecov by Harness.
📢 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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants