@@ -285,21 +285,23 @@ func (c *baseClient) _getConn(ctx context.Context) (*pool.Conn, error) {
285285return cn , nil
286286}
287287
288- func (c * baseClient ) newReAuthCredentialsListener (ctx context.Context , cn * pool.Conn ) auth.CredentialsListener {
289- connPool := pool .NewSingleConnPool (c .connPool , cn )
290- // hooksMixin are intentionally empty here
291- conn := newConn (c .opt , connPool , nil )
288+ func (c * baseClient ) newReAuthCredentialsListener (ctx context.Context , poolCn * pool.Conn ) auth.CredentialsListener {
292289ctx = c .context (ctx )
293290return auth .NewReAuthCredentialsListener (
294- c .reAuthConnection (ctx , conn ),
295- c .onAuthenticationErr (ctx , conn ),
291+ c .reAuthConnection (ctx , poolCn ),
292+ c .onAuthenticationErr (ctx , poolCn ),
296293)
297294}
298295
299- func (c * baseClient ) reAuthConnection (ctx context.Context , cn * Conn ) func (credentials auth.Credentials ) error {
296+ func (c * baseClient ) reAuthConnection (ctx context.Context , poolCn * pool. Conn ) func (credentials auth.Credentials ) error {
300297return func (credentials auth.Credentials ) error {
301298var err error
302299username , password := credentials .BasicAuth ()
300+
301+ connPool := pool .NewSingleConnPool (c .connPool , poolCn )
302+ // hooksMixin are intentionally empty here
303+ cn := newConn (c .opt , connPool , nil )
304+
303305if username != "" {
304306err = cn .AuthACL (ctx , username , password ).Err ()
305307} else {
@@ -308,22 +310,13 @@ func (c *baseClient) reAuthConnection(ctx context.Context, cn *Conn) func(creden
308310return err
309311}
310312}
311- func (c * baseClient ) onAuthenticationErr (ctx context.Context , cn * Conn ) func (err error ) {
313+ func (c * baseClient ) onAuthenticationErr (ctx context.Context , poolCn * pool. Conn ) func (err error ) {
312314return func (err error ) {
313- // since the connection pool of the *Conn will actually return us the underlying pool.Conn,
314- // we can get it from the *Conn and remove it from the clients pool.
315315if err != nil {
316316if isBadConn (err , false , c .opt .Addr ) {
317- poolCn , getErr := cn .connPool .Get (ctx )
318- if getErr == nil {
319- c .connPool .Remove (ctx , poolCn , err )
320- } else {
321- // if we can't get the pool connection, we can only close the connection
322- if err := cn .Close (); err != nil {
323- log .Printf ("failed to close connection: %v" , err )
324- }
325- }
317+ c .connPool .CloseConn (poolCn )
326318}
319+ internal .Logger .Printf (ctx , "redis: re-authentication failed: %v" , err )
327320}
328321}
329322}
0 commit comments