Skip to content

fix(metadata, protocol, proxy): preserve request context across RPC paths - #3579

Merged
Alanxtl merged 14 commits into
apache:developfrom
XnLemon:fix/issue-3557-context-propagation
Aug 20, 2026
Merged

Alanxtl merged 14 commits into
apache:developfrom
XnLemon:fix/issue-3557-context-propagation

Conversation

@XnLemon

@XnLemon XnLemon commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes #3557.

Preserve request context across metadata RPC, REST, JSON-RPC, proxy, and RPCInvocation flows. This prevents cancellation, deadlines, tracing values, and context attachments from being lost when a new context.Background() is created.

Added regression tests for metadata v1/v2, REST, JSON-RPC, and invocation context propagation.

修复 metadata RPC、REST、JSON-RPC、proxy 和 RPCInvocation 链路中的 context 丢失问题,确保取消信号、超时、deadline、tracing 信息及 context attachment 能够继续传递。

新增 metadata v1/v2、REST、JSON-RPC 和 invocation context 传播的回归测试。

Checklist

  • I confirm the target branch is develop
  • Code has passed local testing
  • I have added tests that prove my fix is effective or that my feature works

@XnLemon
XnLemon changed the base branch from main to develop July 30, 2026 09:20
@XnLemon XnLemon changed the title fix(context): preserve request context across RPC paths fix(metadata, protocol, proxy): preserve request context across RPC paths Jul 30, 2026
@codecov-commenter

codecov-commenter commented Jul 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.88060% with 70 lines in your changes missing coverage. Please review.
✅ Project coverage is 55.17%. Comparing base (60d1c2a) to head (834965a).
⚠️ Report is 922 commits behind head on develop.

Files with missing lines Patch % Lines
protocol/jsonrpc/server.go 84.74% 13 Missing and 5 partials ⚠️
remoting/exchange_client.go 33.33% 14 Missing and 4 partials ⚠️
remoting/getty/getty_client.go 18.18% 7 Missing and 2 partials ⚠️
protocol/rest/server/rest_server.go 41.66% 5 Missing and 2 partials ⚠️
...scovery/service_instances_changed_listener_impl.go 86.00% 4 Missing and 3 partials ⚠️
metadata/client.go 73.33% 2 Missing and 2 partials ⚠️
protocol/dubbo/dubbo_invoker.go 0.00% 3 Missing ⚠️
protocol/invocation/rpcinvocation.go 92.00% 1 Missing and 1 partial ⚠️
...try/servicediscovery/service_discovery_registry.go 66.66% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3579      +/-   ##
===========================================
+ Coverage    46.76%   55.17%   +8.40%     
===========================================
  Files          295      474     +179     
  Lines        17172    36878   +19706     
===========================================
+ Hits          8031    20347   +12316     
- Misses        8287    14886    +6599     
- Partials       854     1645     +791     

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

@Alanxtl Alanxtl self-assigned this Jul 30, 2026
@Alanxtl Alanxtl added ☢️ Bug 3.3.3 version 3.3.3 labels Jul 30, 2026
Comment thread metadata/client.go Resolved

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.

Pull request overview

This PR addresses context propagation bugs across several Dubbo-Go RPC entrypoints/bridges (metadata RPC, REST, JSON-RPC, proxy, and RPCInvocation), ensuring cancellations, deadlines, tracing values, and context-based attachments are preserved rather than being dropped via context.Background().

Changes:

  • Add request context.Context storage/accessors on invocation.RPCInvocation and preserve it when building attachment contexts.
  • Propagate inbound request contexts through REST and JSON-RPC server handlers into both Invoker.Invoke(ctx, ...) and the created RPCInvocation.
  • Thread context into metadata RPC calls via a new GetMetadataFromRpcWithContext API and add regression tests for the above paths.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
proxy/proxy.go Sets the invocation context on generated RPCInvocation instances in proxy calls.
protocol/rest/server/rest_server.go Uses the raw HTTP request context for invocation and invocation context; adds nil raw-request guard.
protocol/rest/server/rest_server_test.go Adds regression test asserting REST request context propagates into invoker + invocation.
protocol/jsonrpc/server.go Derives ctx from *http.Request (including tracing extraction) and sets it on RPCInvocation.
protocol/jsonrpc/server_test.go Adds test ensuring request context values/cancellation are preserved by contextFromRequest.
protocol/invocation/rpcinvocation.go Introduces RPCInvocation context storage (Context/SetContext) and uses it when creating attachment contexts.
protocol/invocation/rpcinvocation_test.go Adds test ensuring GetAttachmentAsContext() preserves request context values.
metadata/client.go Adds GetMetadataFromRpcWithContext and forwards ctx into invoker invocation + RPCInvocation.
metadata/client_test.go Adds tests ensuring metadata RPC invocation receives the caller context.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread protocol/rest/server/rest_server.go Resolved
@XnLemon

XnLemon commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

@Alanxtl 请帮我重新rerun一下ci 谢谢 owo

 nacos Pulled 
 polaris Error Head "https://registry-1.docker.io/v2/polarismesh/polaris-standalone/manifests/v1.17.2": Get "https://auth.docker.io/token?account=githubactions&scope=repository%3Apolarismesh%2Fpolaris-standalone%3Apull&service=registry.docker.io": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
 Error response from daemon: Head "https://registry-1.docker.io/v2/polarismesh/polaris-standalone/manifests/v1.17.2": Get "https://auth.docker.io/token?account=githubactions&scope=repository%3Apolarismesh%2Fpolaris-standalone%3Apull&service=registry.docker.io": context deadline exceeded (Client.Timeout exceeded while awaiting headers)

Comment thread metadata/client.go Resolved
Comment thread protocol/jsonrpc/server.go Resolved
Comment thread protocol/invocation/rpcinvocation.go Resolved
Comment thread metadata/client.go Resolved
@Alanxtl Alanxtl linked an issue Aug 6, 2026 that may be closed by this pull request
Comment thread protocol/jsonrpc/server.go Resolved

@Alanxtl Alanxtl left a comment

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.

lgtm

Comment thread protocol/jsonrpc/server.go Resolved
Comment thread protocol/jsonrpc/server.go Resolved
@XnLemon

XnLemon commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author
  Picked up JAVA_TOOL_OPTIONS:  -Dhttp.keepAlive=false -Dmaven.wagon.http.pool=false
  /opt/hostedtoolcache/CodeQL/2.26.2/x64/codeql/java/tools/autobuild.sh 
  Picked up JAVA_TOOL_OPTIONS:  -Dhttp.keepAlive=false -Dmaven.wagon.http.pool=false
  ERROR: Could not detect a suitable build command for the source checkout.
  Error: We were unable to automatically build your code. Please replace the call to the autobuild action with your custom build steps. Encountered a fatal error while running "/opt/hostedtoolcache/CodeQL/2.26.2/x64/codeql/java/tools/autobuild.sh". Exit code was 1 and last log line was: ERROR: Could not detect a suitable build command for the source checkout. See the logs for more details.

仓库 CodeQL workflow 的自动语言探测不稳定:这次意外识别到了嵌套的 Java benchmark 项目,然后 Java autobuild 失败。上一次同版本 CodeQL 只识别到 Go,因此通过了。

Comment thread protocol/jsonrpc/server.go Resolved
@sonarqubecloud

Copy link
Copy Markdown

@Alanxtl
Alanxtl merged commit 2210462 into apache:develop Aug 20, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3.3.3 version 3.3.3 ☢️ Bug

Projects

None yet

5 participants