MCPcopy
hub / github.com/redis/go-redis / onAuthenticationErr

Method onAuthenticationErr

redis.go:458–481  ·  redis.go::baseClient.onAuthenticationErr
()

Source from the content-addressed store, hash-verified

456 }
457}
458func (c *baseClient) onAuthenticationErr() func(poolCn *pool.Conn, err error) {
459 return func(poolCn *pool.Conn, err error) {
460 if err != nil {
461 if isBadConn(err, false, c.opt.Addr) {
462 // Close the connection to force a reconnection.
463 // Re-auth happens on connections that were idle in the pool (the pool hook
464 // waits for IDLE state before transitioning to UNUSABLE for re-auth).
465 // From metrics perspective, the connection was never "used" by a client.
466 // Note: Using context.Background() as this callback doesn't have access to caller's context.
467 err := c.connPool.CloseConn(context.Background(), poolCn, pool.CloseReasonAuthError, pool.MetricStateIdle)
468 if err != nil {
469 internal.Logger.Printf(context.Background(), "redis: failed to close connection: %v", err)
470 // try to close the network connection directly
471 // so that no resource is leaked
472 err := poolCn.Close()
473 if err != nil {
474 internal.Logger.Printf(context.Background(), "redis: failed to close network connection: %v", err)
475 }
476 }
477 }
478 internal.Logger.Printf(context.Background(), "redis: re-authentication failed: %v", err)
479 }
480 }
481}
482
483func (c *baseClient) initConn(ctx context.Context, cn *pool.Conn) error {
484 // This function is called in two scenarios:

Callers 1

initConnMethod · 0.95

Calls 4

isBadConnFunction · 0.85
CloseConnMethod · 0.65
PrintfMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected