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


##########
admin/core/xds.go:
##########
@@ -101,8 +101,18 @@ func StartxDsServer(ctx context.Context) error {
        )
 
        // Establishing the watch before rebuilding closes the startup gap: 
writes
-       // that race with the full read remain queued on the watch channel.
-       go watchConfigAndReload(ctx, publisher)
+       // that race with the full read remain queued on the watch channel. 
Keep the
+       // watcher within this server's lifecycle so the etcd client stays alive
+       // until any in-flight snapshot build has finished.
+       watcherDone := make(chan struct{})
+       go func() {
+               defer close(watcherDone)
+               watchConfigAndReload(ctx, publisher)
+       }()
+       defer func() {
+               cancel()
+               <-watcherDone

Review Comment:
   按 head `72ad5451` 复核,上面两条结论都需要更新(源码级判断,本轮无法本地跑测试:GitHub 到本机通道中断,无法建立 exact 
head 副本):
   
   **1. “cancel() 无法中断在途的 etcd 读”——已修。**
   - `admin/logic/logic.go` 新增 `getChildrenKVList(ctx, client etcdRangeGetter, 
key)`,把 `ctx` 直接传给 `client.Get(ctx, key, 
clientv3.WithPrefix())`;`BizGetClustersWithContext` / 
`BizGetListenersWithContext` 是它的两个调用方。
   - `admin/xds/snapshot.go` 新增 `contextResourceLoader` 接口与 
`loadListeners`/`loadClusters` 的类型断言分支,`LogicResourceLoader` 在 
`BuildWithContext` 路径上走 ctx 版本;`Build` 保留为 
`BuildWithContext(context.Background(), version)` 的包装,旧调用方语义不变。
   - `admin/xds/publisher.go` 的 `Publish` 改为 `builder.BuildWithContext(ctx, 
version)`,并在 build 之后、`SetSnapshot` 之前各加一次 `ctx.Err()` 短路。
   
   **2. “关闭等待没有上界”——等待对象已换成可中断的 watcher,但上界仍不存在。**
   `StartxDsServer` 现在是 `defer func(){ cancel(); <-watcherDone 
}()`,`<-watcherDone` 依然没有超时;之所以不再长时间阻塞,是因为第 1 点让 watcher 内部的 etcd 读与快照构建都响应 
`ctx.Done()`。若 etcd client 自身在极端情况(例如 gRPC 连接卡在 DNS/握手)不响应 
cancel,关闭仍会一直等。这一点属于残余风险,本轮不作为 Finding 定级。
   
   **3. 另有一处与本次修复相关但未定级的差异**:`consumeConfigWatch` 的 `publish` 闭包在 `ctx.Err() != 
nil` 时直接 return 且不置 `pending`,`Publish` 在 ctx 取消时也返回 `ctx.Err()` 而不走 
`recordError`。即“关闭期间的构建/发布失败”不再写入 `StatusStore.LastError`。这与 
`publisher_test.go` 新增用例 `TestSnapshotPublisherCancelsInFlightResourceLoad` 
的断言(`LastError` 为空)一致,属有意取舍;只提示后续排查真实构建失败时不要以 `LastError` 为空作为判据。



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