Skip to content

transport: surface data when received non-grpc header, end stream without trailers - #9217

Merged
easwars merged 3 commits into
grpc:masterfrom
chengxilo:follow-up-surface-non-grpc-data
Jul 31, 2026
Merged

easwars merged 3 commits into
grpc:masterfrom
chengxilo:follow-up-surface-non-grpc-data

Conversation

@chengxilo

@chengxilo chengxilo commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Follow up: #8929

Related to: #7406 (comment) . I don't have the captured packages for reference. But according to the code, I think what I fixed is the only code path that produces codes.Internal / "server closed the stream without sending trailers" when nonGRPCStatus is set.

With this change, if we were collecting non-gRPC response data, and received an end of stream while there is no trailers, finalize the status with whatever body we've buffered so far instead of discarding it. I added tests in both internal/transport_test.go and test/end2end_test.go to test it.

RELEASE NOTES:

  • client: Fix non-gRPC error being discarded when END_STREAM arrives without trailers

If we were collecting non-gRPC response data, finalize the status with whatever
 body we've buffered so far instead of discarding it. Add tests in both
internal/transport_test.go and test/end2end_test.go to test it.
@chengxilo chengxilo changed the title fix: surface data when end stream without trailers fix: surface data when received non-grpc header, end stream without trailers Jul 1, 2026
@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 54.54545% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.14%. Comparing base (116e945) to head (7df5840).
⚠️ Report is 16 commits behind head on master.

Files with missing lines Patch % Lines
internal/transport/http2_client.go 54.54% 4 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9217      +/-   ##
==========================================
+ Coverage   83.03%   83.14%   +0.11%     
==========================================
  Files         422      422              
  Lines       34826    34827       +1     
==========================================
+ Hits        28917    28958      +41     
+ Misses       4407     4381      -26     
+ Partials     1502     1488      -14     
Files with missing lines Coverage Δ
internal/transport/http2_client.go 92.62% <54.54%> (+0.29%) ⬆️

... and 27 files with indirect coverage changes

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

@drigz

drigz commented Jul 3, 2026

Copy link
Copy Markdown

I can confirm this works:

Error: API call failed: rpc error: code = Unauthenticated desc = unexpected HTTP status code received from server: 401 (Unauthorized); transport: received unexpected content-type "text/html"
data: "<html>\r\n<head><title>401 Authorization Required</title></head>\r\n<body>\r\n<center><h1>401 Authorization Required</h1></center>\r\n<hr><center>nginx</center>\r\n</body>\r\n</html>\r\n"

Thank you for the quick followup! Looking forward to pulling the next release in and enjoying more discoverable error messages.

@chengxilo

Copy link
Copy Markdown
Contributor Author

I can confirm this works:

Error: API call failed: rpc error: code = Unauthenticated desc = unexpected HTTP status code received from server: 401 (Unauthorized); transport: received unexpected content-type "text/html"
data: "<html>\r\n<head><title>401 Authorization Required</title></head>\r\n<body>\r\n<center><h1>401 Authorization Required</h1></center>\r\n<hr><center>nginx</center>\r\n</body>\r\n</html>\r\n"

Thank you for the quick followup! Looking forward to pulling the next release in and enjoying more discoverable error messages.

Great!!! Thank you so much for your quick followup too! ❤️❤️❤️

@chengxilo chengxilo changed the title fix: surface data when received non-grpc header, end stream without trailers transport: surface data when received non-grpc header, end stream without trailers Jul 14, 2026
@chengxilo

Copy link
Copy Markdown
Contributor Author

Sorry I forgot update the PR title.

@easwars easwars added this to the 1.84 Release milestone Jul 14, 2026
@drigz

drigz commented Jul 14, 2026

Copy link
Copy Markdown

@easwars Any chance this fix could be considered for a cherry-pick into 1.82?

I couldn't find a doc with guidelines for cherry-pick requirements - but since I ran into this while debugging a 500 error today I thought it might be worth asking.

@easwars

easwars commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

@drigz : If we get this reviewed and merged in time before the 1.83 release, which should happen sometime next week, we can consider cherry-picking it.

@easwars easwars self-assigned this Jul 15, 2026
Comment thread internal/transport/http2_client.go Outdated
Comment thread test/end2end_test.go Outdated
Comment thread internal/transport/transport_test.go
@chengxilo

Copy link
Copy Markdown
Contributor Author

All issues addressed. Additionally, I removed the redundant seenHeaders channel in TestNonGRPCStatus_EmptyDataEndStream.

@arjan-bal arjan-bal assigned arjan-bal and unassigned easwars and chengxilo Jul 24, 2026
@arjan-bal

Copy link
Copy Markdown
Contributor

/gemini review

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request ensures that when a non-gRPC response is followed by an empty DATA frame with END_STREAM, the client correctly surfaces the original non-gRPC error instead of discarding the collected buffer and returning an internal error. This is achieved by refactoring the handleData method in http2_client.go to process non-gRPC status checks outside of the data size block and only processing data frames when size > 0. Corresponding unit and end-to-end tests have been added and updated to verify this behavior. There are no review comments to address, and the changes look solid.

@arjan-bal arjan-bal 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.

LGTM! Adding a second reviewer.

@easwars
easwars merged commit d7025c5 into grpc:master Jul 31, 2026
14 checks passed
@easwars

easwars commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

@chengxilo : Thanks for your contribution!

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.

4 participants