Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion network/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -71,7 +73,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.
Expand All @@ -81,10 +84,14 @@ 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
})
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")
Expand Down