From 982b7fcb6b948d5fb3737c79530d9d2fea9f4dd0 Mon Sep 17 00:00:00 2001 From: Mostafa Moradian Date: Wed, 11 Jan 2023 18:47:26 +0100 Subject: [PATCH 1/3] Prevent creating an orphaned connection when we can't put a client into the pool --- network/proxy.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/network/proxy.go b/network/proxy.go index 373186ec..cfc978a2 100644 --- a/network/proxy.go +++ b/network/proxy.go @@ -81,6 +81,8 @@ func NewProxy( client = NewClient(proxy.ClientConfig, proxy.logger) if err := proxy.availableConnections.Put(client.ID, client); err != nil { proxy.logger.Err(err).Msg("Failed to update the client connection") + // Close the client, because we don't want to have orphaned connections. + client.Close() } } return true From e3039f75ad195bfdfb31c737e07b85fb754a6035 Mon Sep 17 00:00:00 2001 From: Mostafa Moradian Date: Wed, 11 Jan 2023 18:48:36 +0100 Subject: [PATCH 2/3] Log execution time of connection recycling job --- network/proxy.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/network/proxy.go b/network/proxy.go index cfc978a2..8376beb9 100644 --- a/network/proxy.go +++ b/network/proxy.go @@ -71,7 +71,8 @@ func NewProxy( // Schedule the client health check. if _, err := proxy.scheduler.Every(proxy.HealthCheckPeriod).SingletonMode().StartAt(startDelay).Do( func() { - logger.Debug().Msg("Running the client health check, and might recycle connection(s).") + now := time.Now() + logger.Debug().Msg("Running the client health check to recycle connection(s).") proxy.availableConnections.ForEach(func(_, value interface{}) bool { if client, ok := value.(*Client); ok { // Connection is probably dead by now. @@ -87,6 +88,8 @@ func NewProxy( } return true }) + logger.Debug().Str("duration", time.Since(now).String()).Msg( + "Finished the client health check") }, ); err != nil { proxy.logger.Error().Err(err).Msg("Failed to schedule the client health check") From 7da7773db57c61b2dd5ff40b6a317346ce296283 Mon Sep 17 00:00:00 2001 From: Mostafa Moradian Date: Wed, 11 Jan 2023 18:49:21 +0100 Subject: [PATCH 3/3] Ignore funlen linter error --- network/proxy.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/network/proxy.go b/network/proxy.go index 8376beb9..45cca32e 100644 --- a/network/proxy.go +++ b/network/proxy.go @@ -40,6 +40,8 @@ type Proxy struct { var _ IProxy = &Proxy{} // NewProxy creates a new proxy. +// +//nolint:funlen func NewProxy( connPool pool.IPool, hookConfig *hook.Config, elastic, reuseElasticClients bool,