Skip to content

server: Implement unwrap server transport stream#9108

Draft
hugehoo wants to merge 5 commits intogrpc:masterfrom
hugehoo:implement-unwrapServerTransportStream
Draft

server: Implement unwrap server transport stream#9108
hugehoo wants to merge 5 commits intogrpc:masterfrom
hugehoo:implement-unwrapServerTransportStream

Conversation

@hugehoo
Copy link
Copy Markdown
Contributor

@hugehoo hugehoo commented May 5, 2026

fixes #9047

changes

  • server.go: Add unwrapServerTransportStream helper that traverses
    wrapper layers using the Unwrap() pattern.

    • A visited-set prevents infinite loops from buggy Unwrap implementations. Update SetSendCompressor and ClientSupportedCompressors to use this helper instead of direct type assertions.
  • stats/opentelemetry/server_metrics.go: Add Unwrap() method to so the helper can reach the underlying *transport.ServerStream.

  • server_test.go: Add unit tests for the unwrap helper, cycle protection test, and regression tests for SetSendCompressor / ClientSupportedCompressors with a wrapped context.

RELEASE NOTES: N/A

hugehoo added 3 commits May 5, 2026 14:14
…ortStream

SetSendCompressor and ClientSupportedCompressors fail when the
ServerTransportStream in context is wrapped (e.g. by OpenTelemetry's
attachLabelsTransportStream), because they directly type-assert to
*transport.ServerStream.

Add an unwrapServerTransportStream helper that traverses wrapper layers
using the Unwrap() pattern (similar to errors.Unwrap) to find the
underlying *transport.ServerStream. A visited-set guards against
infinite loops from buggy Unwrap implementations.

Update both SetSendCompressor and ClientSupportedCompressors to use
this helper instead of direct type assertions.

Fixes grpc#9047
Add Unwrap() to attachLabelsTransportStream so that
unwrapServerTransportStream can traverse through it to find the
underlying *transport.ServerStream. This fixes SetSendCompressor and
ClientSupportedCompressors when the OpenTelemetry stats plugin is active.
Add unit tests for the unwrapServerTransportStream helper covering
direct, single-wrapped, nested-wrapped, non-unwrappable, and nil cases.

Add a cycle protection test verifying that a self-referencing Unwrap
terminates instead of looping infinitely.

Add regression tests for SetSendCompressor and ClientSupportedCompressors
with a wrapped context, directly exercising the scenario from grpc#9047.
@codecov
Copy link
Copy Markdown

codecov Bot commented May 5, 2026

Codecov Report

❌ Patch coverage is 76.47059% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.05%. Comparing base (850cc54) to head (2ae6593).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
server.go 86.66% 0 Missing and 2 partials ⚠️
stats/opentelemetry/server_metrics.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9108      +/-   ##
==========================================
- Coverage   83.12%   83.05%   -0.07%     
==========================================
  Files         413      413              
  Lines       33484    33497      +13     
==========================================
- Hits        27832    27821      -11     
- Misses       4229     4246      +17     
- Partials     1423     1430       +7     
Files with missing lines Coverage Δ
server.go 82.57% <86.66%> (+0.18%) ⬆️
stats/opentelemetry/server_metrics.go 86.71% <0.00%> (-1.38%) ⬇️

... and 16 files with indirect coverage changes

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

hugehoo and others added 2 commits May 5, 2026 15:13
Fix vet.sh failure by wrapping bare context.Background() with
context.WithTimeout. Also align with codebase conventions: reorder
helper types, rename tt to test, and simplify error messages.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove extra spacing in mockServerTransportStream method alignment
to satisfy goimports formatting check in vet.sh.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@hugehoo hugehoo marked this pull request as ready for review May 5, 2026 06:44
@hugehoo hugehoo marked this pull request as draft May 6, 2026 15:49
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.

server: ClientSupportedCompressors and SetSendCompressor break when using Opentelemetry metrics plugin

1 participant