AlexStocks commented on code in PR #3832:
URL: https://github.com/apache/dubbo-go/pull/3832#discussion_r4596343870
##########
remoting/getty/getty_client.go:
##########
@@ -267,6 +267,11 @@ func (c *Client) RequestContext(ctx context.Context,
request *remoting.Request,
case <-response.Done:
err = response.Err
case <-ctx.Done():
+ // Drop the pending waiter, but keep the shared session. Caller
+ // cancellation is not a transport failure; a later request may
+ // reuse this connection. The read-timeout branch still closes
+ // the session because that path can no longer trust it.
+
remoting.RemovePendingResponse(remoting.SequenceType(request.ID))
Review Comment:
两点都能在 head `c24cc77c` 上复现定位,补充证据与一个更窄的改法。
**迟到响应打 ERROR 的来源是 `Response.Handle()`**:`remoting/exchange.go:96-99` 取不到
pending 时执行
```go
logger.Errorf("[Remoting] failed to get pending response context for
response package %s", *response)
```
而新增的 `ctx.Done()` 分支(`getty_client.go:269-274`)会先
`RemovePendingResponse`。因此「客户端取消 → 服务端随后返回」这条正常路径必然产生一条 ERROR,这与真正异常(ID
无人认领、协议错乱)混在同一条日志里,取消量大的服务会把它刷成噪声。另外 `%s` 走 `Response.String()`,会把整个 `Result`
打出来(`exchange.go:113-115`),大响应时单条日志体积会进一步放大。
**建议区分「已取消」与「未知 ID」**,而不是把 ERROR 整体降级:在 `getty_client.go:274` 移除前拿一次
`remoting.GetPendingResponse(seq)`,命中则在对象上打 `cancelled` 标记(或写入一个有短 TTL 的
cancelled 集合),`Handle()` 命中标记时降为 `Debug`,未命中才保留 ERROR。这样既保留异常可观测性,又消掉正常取消的噪声。
**第二点(既有边界)核对结论**:`getty_client.go:227-229` 的 `ctx.Err()` 早退发生在 pending
注册之前(注册在 `transfer` 内的 `exchange.go:188`),所以走 `RequestContext` 正常入口不会残留
pending;只有调用方自行先 `AddPendingResponse` 再传入已取消的 ctx 才会漏清理。这是契约层面的既有边界,建议在
`RequestContext` 的注释里明确「本函数假定进入时该 ID 尚未注册 pending」,避免后续调用方误用。
--
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]