Tsukikage7 commented on code in PR #1017:
URL: https://github.com/apache/dubbo-go-pixiu/pull/1017#discussion_r3739419275
##########
pkg/filter/http/grpcproxy/descriptor.go:
##########
@@ -117,12 +130,103 @@ func (dr *Descriptor)
getServerDescriptorSourceCtx(refCtx context.Context, cfg *
default:
err = errors.Errorf("found a value of type %s, which is not
*grpc.ClientConn, ", t)
}
- return &serverSource{client: grpcreflect.NewClient(refCtx,
reflectpb.NewServerReflectionClient(cc))}, err
+ if err != nil {
+ return nil, err
+ }
+
+ dr.remoteMu.Lock()
+ defer dr.remoteMu.Unlock()
+ if dr.remoteSources == nil {
+ dr.remoteSources = make(map[*grpc.ClientConn]DescriptorSource)
+ }
+ if source, ok := dr.remoteSources[cc]; ok {
+ return source, nil
+ }
+
+ // The descriptor source is cached for the lifetime of the connection.
It
+ // must not retain the per-request context, which is cancelled when
Decode
+ // returns and would make every later reflection call fail.
+ source := &serverSource{client:
grpcreflect.NewClient(context.Background(),
reflectpb.NewServerReflectionClient(cc))}
Review Comment:
已修复,感谢指出。`grpcreflect.Client` 在 v1.17.0 中所有 RPC 都复用根
context(`FileContainingSymbol` 等接口不接收 per-call ctx),所以连接级缓存 +
`context.Background()` 确实会让 remote lookup 脱离请求超时保护。
修复方式(`eb4c541a`):
- 保留长期缓存的 **method descriptor 缓存**(`getMethodDescriptor`,per-connection +
per-service-method,并发下单次查找后不再触发反射 RPC,这是性能收益所在);
- 移除连接级 `remoteSources` 客户端缓存,每次远程 lookup 按请求 context 重新创建 reflection
client(`descriptor.go` 中 `getServerDescriptorSourceCtx` 直接使用 `refCtx`,即
`Decode` 里 `context.WithTimeout(c.Ctx, c.Timeout)`)。
这样缓存仍可长期存在,但每次真实反射查找都受 `c.Timeout` 明确 deadline 约束,与原先实现语义一致。
新增回归测试 `TestDescriptorSourceHonorsRequestTimeout`:阻塞 reflection 服务下,带 100ms
超时的请求在 FindSymbol 时返回 DeadlineExceeded。
##########
pkg/client/dubbo/typeconv.go:
##########
Review Comment:
已修复。Sonar 报告的 3 个新问题:
- `go:S3776`(CRITICAL,cognitive complexity 21 > 15)在
`CoerceDirectInvokeValue`:已把两处按标量元素强制转换的循环提取为 `coerceScalarSlice`
helper,复杂度回落到阈值内;
- `go:S8239`(MAJOR ×2)在 `descriptor.go` 的 `context.Background()`:一并修复,与 P1
同一提交。
`typeconv.go` 行为不变(数组分支非 `[]any` 时仍原样返回、标量分支走
`MapTypes`),新增/既有单测均通过。提交:`eb4c541a`。
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]