mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-09-03 06:35:00 +08:00
fix(main): ensure safe closure of homeClient to prevent idle connections
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user