fix(main): ensure safe closure of homeClient to prevent idle connections

This commit is contained in:
hkfires
2026-08-01 13:34:30 +08:00
parent bc71c77f5c
commit 448893290d

View File

@@ -284,7 +284,11 @@ func main() {
homeCfg.DisableClusterDiscovery = true
}
homeClient = home.New(homeCfg)
defer homeClient.Close()
defer func() {
if homeClient != nil {
homeClient.Close()
}
}()
ctxHomeConfig, cancelHomeConfig := context.WithTimeout(context.Background(), 30*time.Second)
raw, errGetConfig := homeClient.GetConfig(ctxHomeConfig)
@@ -622,6 +626,12 @@ func main() {
return
}
}
if homeClient != nil {
// The bootstrap client is not owned by the runtime service. Close it after
// the final startup report so it cannot retain an idle RESP connection.
homeClient.Close()
homeClient = nil
}
if pluginHost.HasTriggeredCommandLineFlags() {
if exitCode, handled := pluginHost.ExecuteCommandLine(context.Background(), os.Args[0], os.Args[1:], configFilePath, flag.CommandLine); handled {
if exitCode != 0 {