HH-833: fence gateway generations across replicas (#22)

This commit is contained in:
2026-08-29 23:27:30 +08:00
parent 9fc8e44123
commit 00d044d440
7 changed files with 83 additions and 27 deletions
+12 -3
View File
@@ -53,7 +53,11 @@ func (registry *memoryProxyRegistry) configure(alias string, bindingVersion int6
(port == 0 || proxy.listener.Addr().(*net.TCPAddr).Port == port) && proxy.exit == exit && proxy.networkID == networkID {
return proxy.url, func() { registry.removeObject(alias, proxy) }, nil
}
return "", nil, errGenerationConflict
delete(registry.proxies, alias)
// A gateway replica may still hold the previous runtime generation. Close
// it before rebinding a restored listener, while removeObject's identity
// check keeps old cleanup callbacks from deleting the replacement.
closeMemoryProxy(proxy)
}
listener, err := net.Listen("tcp4", net.JoinHostPort(bindHost, strconv.Itoa(port)))
if err != nil {
@@ -80,10 +84,15 @@ func (registry *memoryProxyRegistry) removeObject(alias string, proxy *memoryPro
}
registry.mu.Unlock()
if proxy != nil {
_ = proxy.server.Close()
closeMemoryProxy(proxy)
}
}
func closeMemoryProxy(proxy *memoryProxy) {
_ = proxy.listener.Close()
_ = proxy.server.Close()
}
func (registry *memoryProxyRegistry) ready(alias string, port int, runtimeID string, networkIDs ...string) bool {
registry.mu.Lock()
defer registry.mu.Unlock()
@@ -120,7 +129,7 @@ func (registry *memoryProxyRegistry) remove(alias string, bindingVersion int64,
}
registry.mu.Unlock()
if proxy != nil {
_ = proxy.server.Close()
closeMemoryProxy(proxy)
}
return true
}