AlexStocks commented on code in PR #1023:
URL: https://github.com/apache/dubbo-go-pixiu/pull/1023#discussion_r4505144392
##########
pkg/filter/http/grpcproxy/connection_manager.go:
##########
@@ -373,6 +373,14 @@ func (m *grpcConnectionManager)
RemoveEndpoint(clusterName, endpoint string) {
// a connection created after the endpoint was re-added.
func (m *grpcConnectionManager) UpdateEndpointState(clusterName, endpoint
string, present bool, eventVersion uint64) {
key := grpcConnectionKey(clusterName, endpoint)
+ // Lifecycle callbacks are delivered outside the cluster manager lock
and can
+ // therefore arrive out of order. Once a bounded tombstone has been
evicted,
+ // its version watermark is no longer available to reject an old
removal.
+ // The cluster snapshot is authoritative in that case: do not let a
delayed
+ // removal turn an endpoint that is currently present back into a
tombstone.
+ if !present && m.isEndpointPresent(key, endpoint) {
Review Comment:
🟡 **`isEndpointPresent` 的 nil 语义在这里是反的,会静默吞掉所有 removal。**
`isEndpointPresent` 在 hook 为 nil 时返回 **true**:
```go
func (m *grpcConnectionManager) isEndpointPresent(key, endpoint string) bool
{
if m.endpointPresent == nil {
return true // "assume present" —— 对 Get 路径是对的
}
return m.endpointPresent(key, endpoint)
}
```
对 `Get` 路径(`!m.isEndpointPresent(...)` → 拒绝建连接)这个默认值合理;但新守卫把它读成「存在 ⇒ 这个
removal 是陈旧的 ⇒ 直接 return」。于是**任何 `endpointPresent == nil` 的 manager,所有
`present=false` 事件都会被丢弃**:`endpointRemoved` 永不置位、tombstone 永不建立、遗留连接永不关闭 ——
正好取消掉这套机制的全部保护。
当前生产路径里两者是一起装配的(`grpc.go:156-165` 的 `if clusterManager != nil` 同时设置 hook 和
handler),所以现在不可触发;但这只差一次重构(比如把 handler 注册与 hook 拆开、或给某个单测/replay 场景注入一个只有
handler 的 manager)就会变成线上 bug,而且是「静默降级」那种最难查的形态。
建议显式判空,让「没有快照可比」保持原语义:
```go
// Without an authoritative snapshot there is nothing to compare against;
// fall through and honor the event.
if !present && m.endpointPresent != nil && m.endpointPresent(key, endpoint) {
return
}
```
同时在 `endpointPresent` 字段的注释里把这条约束写明(现在只说它是 "optional authoritative snapshot
check",没说 nil 时 removal 必须照常生效)。
##########
pkg/filter/http/grpcproxy/connection_manager_test.go:
##########
@@ -253,6 +257,108 @@ func
TestGRPCConnectionManagerRejectsEvictedRemovedEndpointFromSnapshot(t *testi
require.Zero(t, dialCalls.Load())
}
+func TestFilterFactoryIgnoresStaleRemovalAfterTombstoneEviction(t *testing.T) {
Review Comment:
💭 这个 fixture 是**在 factory 已构造完成之后**覆写
`factory.connections.endpointPresent`,并把它当同步屏障用(`close(removalEntered)` +
`<-releaseRemoval`)。功能上没问题,但有两个隐含约束值得写进注释:
1. 此刻必须保证没有并发的请求 goroutine 在读这个字段,否则 `-race` 会报数据竞争(现在成立,因为 fixture 在
`DeleteEndpoint` 之前没有发起请求);
2. 屏障之所以能挂在这里,是因为「removal 回调一定会先问快照」——而这正好是本 PR
新增的行为。如果将来守卫被改成「先更新版本号再问快照」,这个测试就会退化成不可控的时序依赖。
建议在注释里写明这两点,或者干脆改成构造期注入(`newFilterFactory` 加一个可选的 hook
参数),让测试不再依赖「字段可在运行期改写」这个前提。
--
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]