Repository navigation
Conversation
…client Signed-off-by: Kevin <yaojiaangyao@gmail.com>
There was a problem hiding this comment.
🟡 Changes recommended
Dubbo calls can exceed the requested deadline because failover retries, synchronous reference creation, and unfiltered timeout attachments bypass the effective request budget.
3 open issues
What changed in this PR
This PR addresses #1654 by passing the Console generic-invocation timeout into Dubbo and Triple client configuration, rather than relying only on the Go context.
Changes:
- Carries
timeoutMsthrough the invocation and applies client/reference timeout options. - Resolves remaining deadline budgets, rejects canceled or expired contexts before setup, and rounds positive timeouts to whole milliseconds.
- Adds timeout boundary tests and SDK-generated Reference URL checks.
| File | Description |
|---|---|
pkg/console/service/service_generic_invoke.go |
Resolves and propagates per-request SDK timeouts. |
pkg/console/service/service_generic_invoke_validation_test.go |
Tests timeout resolution and Dubbo/Triple Reference URL settings. |
Review effort: Max
| client.WithProtocol(invocation.Protocol), | ||
| client.WithSerialization(invocation.Serialization), | ||
| ) | ||
| } |
| } | ||
|
|
||
| var invokeGenericServiceRPC = func(callCtx context.Context, invocation genericInvocation) (any, error) { | ||
| timeout, err := resolveGenericInvokeTimeout(callCtx, invocation) |
| } | ||
| if timeout > 0 { | ||
| clientOpts = append(clientOpts, client.WithClientRequestTimeout(timeout)) | ||
| referenceOpts = append(referenceOpts, client.WithRequestTimeout(timeout)) |
…ing budget Signed-off-by: Kevin <yaojiaangyao@gmail.com>
robocanic
left a comment
There was a problem hiding this comment.
Code Review:#1655 fix(console): propagate timeoutMs to Dubbo and Triple generic invoke client
已对 head 511e5334 的全部三个变更文件做了审查,并对照 PR 所用 dubbo-go 版本(v3.0.0-20260210015753-35ea886421f9)的 DubboInvoker.getTimeout / Triple applyDefaultTimeout 源码核对了超时透传链路。
Strengths
- 根因分析准确:同时通过
client.WithClientRequestTimeout/client.WithRequestTimeout设置 Reference URL 的timeout,并通过 invocation attachment 覆盖,覆盖了 Dubbo(getTimeout用time.ParseDuration解析 attachment)和 Triple(TimeoutKey{}走ParseDuration)两条路径,格式timeout.String()与 SDK 解析一致。 resolveGenericInvokeTimeout对已取消/已过期 context 提前短路,并向上取整到毫秒,规避亚毫秒被截断为"0"的边界问题。- 剥离用户传入的
timeoutattachment(大小写不敏感),防止其绕过timeoutMs;applyGenericInvokeTimeoutAttachment拷贝 map 而不修改调用方数据。 - 测试既有基于 recorder 的 Reference URL 断言,也有真实 Dubbo/Triple 协议端到端的超时用例,覆盖面好。
Critical
未发现。
Important
-
newGenericServiceWithContext在 ctx 到期后遗弃 goroutine 及其创建的 Reference,造成资源泄漏- 位置:
pkg/console/service/service_generic_invoke.go,newGenericServiceWithContext(select的<-ctx.Done()分支,以及res := <-resultCh后ctx.Err() != nil的分支)。 - 问题:
cli.NewGenericService本身不可取消。ctx 先到期时函数直接返回,后台 goroutine 仍继续建连,最终产生的*GenericService(含 Invoker / 连接)无人持有、永远不会Destroy;第二个分支甚至已经拿到了res.svc却直接丢弃。对不可达/慢速目标,每次超时的泛化调用都会残留一个 goroutine 和一个未释放的连接/Reference,Console 长期运行会累积。 - 建议:在两个丢弃分支中,让 goroutine(或
ctx.Err()分支)负责在res.svc != nil时调用其 Invoker/Reference 的销毁方法(或在 goroutine 内select检测 ctx 已完成后自行销毁);同时落实文件中已有的「缓存/复用 client」TODO,避免每次调用都新建dubbo.Instance。至少应补一个用例验证超时后被丢弃的 service 会被清理。
- 位置:
-
未在 PR 描述中说明的行为变更:新增
client.WithClusterFailFast()- 位置:
invokeGenericServiceRPC中的referenceOpts。 - 问题:此前使用 SDK 默认的 failover 集群(默认重试),现在改为 fail-fast,即泛化调用失败后不再重试。这对非幂等方法是合理的,也让「总耗时 ≤ timeoutMs」成立,但它不属于 issue #1654 的范围,PR 描述的 Changes 中也没有提及,评审与后续排障者容易遗漏。
- 建议:在 PR 描述和提交说明中明确写出该变更及原因(避免 failover 重试使总时长超过
timeoutMs或重复触发非幂等调用);若不想改变重试语义,则去掉该选项。
- 位置:
-
新增的真实协议测试偏慢且有时序/端口竞争风险
- 位置:
service_generic_invoke_timeout_test.go(reserveLocalTCPPort先Close再由 SDK 重新绑定;above-3s-succeeds-beyond-sdk-default每个协议固定 sleep 3.2s;isGenericInvokeTimeoutErr以字符串包含"timeout"/"deadline"判定)。 - 问题:先释放端口再重绑存在被其他进程抢占的 TOCTOU 窗口;
elapsed < 2s、800ms延迟等基于墙钟的断言在 CI 负载下可能抖动;字符串匹配过宽,可能把「连接超时」等无关错误也判为通过,削弱对本修复的回归保护。 - 建议:优先让 SDK/监听器直接使用
:0并读取实际端口(或在 export 失败时重试);将超时错误判定收窄为context.DeadlineExceeded或tri.CodeDeadlineExceeded;适当放宽时间阈值。
- 位置:
Assessment
Ready to merge? With fixes
Reasoning: 超时透传的核心逻辑与 SDK 行为一致、边界处理周全,未发现会导致功能错误的 Critical 问题;但 ctx 到期后遗弃 goroutine/Reference 的资源泄漏应当修复,FailFast 的行为变更需要在描述中说明,测试的稳定性也建议加固。
…timeout tests Signed-off-by: Kevin <yaojiaangyao@gmail.com>
|
|
@robocanic 感谢细致的 review!三条建议均已在
|





Please provide a description of this PR:
Problem
在泛化调用(
POST /api/v1/service/generic/invoke)中,pkg/console/service/service_generic_invoke.go虽为callCtx设置了context.WithTimeout,但在创建dubbo-goClient /GenericService时未传入请求超时参数。由于 Dubbo 协议的DubboInvoker依据 Reference URL 的timeout参数控制超时(默认3s),导致单次请求的timeoutMs在小于3s时不超时、大于3s时被提前截断。Changes
genericInvocation补充Timeout字段,并由InvokeServiceGeneric传入请求timeoutMs。resolveGenericInvokeTimeout与ceilTimeoutToMillisecond:优先检查callCtx.Err()(已取消或已过期则在建连前短路返回),结合callCtx.Deadline()与invocation.Timeout取较小剩余预算,并将正超时按整毫秒向上取整(避免亚毫秒被 Dubbo 截断为"0"或向 Triple HTTP/2 header 写入非 ASCII 字符µ)。invokeGenericServiceRPC中将有效超时同时透传至client.WithClientRequestTimeout与client.WithRequestTimeout,覆盖默认3s。failfast):为直连引用显式设置client.WithClusterFailFast(),禁用默认failover重试。原因:固定 SDK 版本中DubboInvoker首次超时后会将timeoutattachment 改写为裸毫秒字符串,触发重试时会因time.ParseDuration解析失败而回落到3s,导致timeoutMs < 3s仍可能意外成功,同时避免对非幂等调试方法重复调用或使总耗时超过timeoutMs。newGenericServiceWithContext使cli.NewGenericService遵循请求 deadline,避免被 SDK 独立连接超时阻塞;并通过ReferenceOption捕获*client.ReferenceOptions,在正常返回、超时遗弃、取消或 panic 时均调用GetInvoker().Destroy()释放底层 Invoker/连接。timeoutattachment 覆盖:在InvokeServiceGeneric和applyGenericInvokeTimeoutAttachment中克隆 attachment map、剥离大小写不敏感的timeout键,并在svc.Invoke前写入最新剩余预算,防止用户attachments绕过timeoutMs。< 3s超时且单次尝试、attachments["timeout"]无法绕过、> 3s突破 SDK 默认3s成功,以及超时/取消后Invoker.Destroy()清理断言)。Verification
24a65e4gofmt -l&git diff --check:PASSgo vet ./pkg/console/service ./pkg/console/handler:PASSgo test -count=1 ./pkg/console/service ./pkg/console/handler:PASS(service9.127s、handler0.504s,含真实 Dubbo/Triple 协议延迟用例与超时释放断言)RUN_DUBBO_GO_E2E=1):NOT VERIFIED(本轮通过进程内真实 Dubbo/Triple 协议端到端单测覆盖)Related Issues
To help us figure out who should review this PR, please put an X in all the areas that this PR affects.