Skip to content

Commit d4c2dbb

Browse files
redis: log recovery when a connection succeeds after a prior dial error
Operators currently only see repeated dial-error logs and have no explicit signal when the pool starts succeeding again. Track whether the last dial attempt failed and log once when a subsequent connection succeeds. Signed-off-by: kiran malsetty <kiran.malsetty@outsystems.com>
1 parent 91e3066 commit d4c2dbb

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

src/redis/driver_impl.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"net"
88
"strings"
9+
"sync/atomic"
910
"time"
1011

1112
"github.com/jpillora/backoff"
@@ -23,13 +24,15 @@ type poolStats struct {
2324
connectionActive stats.Gauge
2425
connectionTotal stats.Counter
2526
connectionClose stats.Counter
27+
hadConnError *atomic.Bool
2628
}
2729

2830
func newPoolStats(scope stats.Scope) poolStats {
2931
ret := poolStats{}
3032
ret.connectionActive = scope.NewGauge("cx_active")
3133
ret.connectionTotal = scope.NewCounter("cx_total")
3234
ret.connectionClose = scope.NewCounter("cx_local_close")
35+
ret.hadConnError = new(atomic.Bool)
3336
return ret
3437
}
3538

@@ -39,13 +42,17 @@ func poolTrace(ps *poolStats, healthCheckActiveConnection bool, srv server.Serve
3942
if newConn.Err == nil {
4043
ps.connectionTotal.Add(1)
4144
ps.connectionActive.Add(1)
45+
if ps.hadConnError.CompareAndSwap(true, false) {
46+
logger.Infof("redis connection re-established after previous error")
47+
}
4248
if healthCheckActiveConnection && srv != nil {
4349
err := srv.HealthChecker().Ok(server.RedisHealthComponentName)
4450
if err != nil {
4551
logger.Errorf("Unable to update health status: %s", err)
4652
}
4753
}
4854
} else {
55+
ps.hadConnError.Store(true)
4956
logger.Errorf("creating redis connection error : %v", newConn.Err)
5057
}
5158
},

0 commit comments

Comments
 (0)