AlexStocks commented on code in PR #992:
URL: https://github.com/apache/dubbo-go-pixiu/pull/992#discussion_r4523646439


##########
pkg/client/mq/mq.go:
##########
@@ -126,9 +126,9 @@ func (c Client) Call(req *client.Request) (res any, err 
error) {
                        consumerFacadeMap.Store(cReq.ConsumerGroup, facade)
                        if f, ok := consumerFacadeMap.Load(cReq.ConsumerGroup); 
ok {
                                cf := f.(ConsumerFacade)
-                               ctx, cancel := context.WithTimeout(c.ctx, 
req.Timeout)
-                               defer cancel()
-                               err = cf.Subscribe(ctx, 
WithTopics(cReq.TopicList), WithConsumeUrl(cReq.ConsumeUrl), 
WithCheckUrl(cReq.CheckUrl), WithConsumerGroup(cReq.ConsumerGroup))
+                               // A subscription outlives this registration 
request. Its workers
+                               // stop on client cancellation, unsubscribe, or 
a failed health check.
+                               err = cf.Subscribe(c.ctx, 
WithTopics(cReq.TopicList), WithConsumeUrl(cReq.ConsumeUrl), 
WithCheckUrl(cReq.CheckUrl), WithConsumerGroup(cReq.ConsumerGroup))

Review Comment:
   [P2] 生产环境没有可取消的父 context,这里注释宣称的 "client cancellation" 停止路径不可达
   
   `Client.ctx` 在 `NewMQClient`(`pkg/client/mq/mq.go:59`)固定为 
`context.Background()`,`Client.Close()`(同文件 89 行)直接 `return nil`,不停止任何 
facade。所以本行改为传入 `c.ctx` 后,并没有真实的取消来源:`KafkaConsumerFacade.Subscribe` 
在生产代码里只有这一处调用点,传入的 ctx 永远不会被 cancel。
   
   **触发条件**:网关正常运行且未收到 unsubscribe 请求;注册请求未提供 `CheckUrl` 或健康检查持续为 200。
   
   **实际影响**:本 PR 删除了原先注册请求返回时的 `defer cancel()`(原 129-130 
行),这是此前唯一的取消来源。替换后,kafka 消费 worker 与 broker 连接只能由「unsubscribe 
请求」或「健康检查失败」终止;`pkg/filter/event/event.go` 没有任何 Close/Stop/Destroy 钩子,MQ client 
关闭时也不会清理,消费者随进程一直存活,多次注册不同 consumerGroup 时累积。
   
   **证据**:
   - `pkg/client/mq/mq.go:59` `ctx := context.Background()`;`:89` `func (c 
Client) Close() error { return nil }`
   - 全仓 `grep -rn "\\.Subscribe(" --include=*.go`(排除测试)中,`KafkaConsumerFacade` 
的调用只有本行
   - 新增测试 `TestMQSubscriptionOutlivesRegistrationRequest` 用 `Client{ctx: 
clientCtx}`(`pkg/client/mq/mq_test.go:57`)直接构造带可取消 ctx 的 Client,绕开了 
`NewMQClient`,因此 "client cancellation" 子用例验证的是生产路径拿不到的前提
   
   **修复方向**:让 `Client` 持有可取消的 ctx(`NewMQClient` 里 `context.WithCancel`,由 
`Client.Close()` 触发 cancel),或在 filter 销毁时显式 `Stop()` 已注册的 facade;并把该测试改为经 
`NewMQClient`(或注入 factory)构造,使取消分支与生产一致。



-- 
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]

Reply via email to