@@ -285,21 +285,23 @@ func (c *baseClient) _getConn(ctx context.Context) (*pool.Conn, error) {
285
285
return cn , nil
286
286
}
287
287
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 {
292
289
ctx = c .context (ctx )
293
290
return auth .NewReAuthCredentialsListener (
294
- c .reAuthConnection (ctx , conn ),
295
- c .onAuthenticationErr (ctx , conn ),
291
+ c .reAuthConnection (ctx , poolCn ),
292
+ c .onAuthenticationErr (ctx , poolCn ),
296
293
)
297
294
}
298
295
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 {
300
297
return func (credentials auth.Credentials ) error {
301
298
var err error
302
299
username , 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
+
303
305
if username != "" {
304
306
err = cn .AuthACL (ctx , username , password ).Err ()
305
307
} else {
@@ -308,22 +310,13 @@ func (c *baseClient) reAuthConnection(ctx context.Context, cn *Conn) func(creden
308
310
return err
309
311
}
310
312
}
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 ) {
312
314
return 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.
315
315
if err != nil {
316
316
if 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 )
326
318
}
319
+ internal .Logger .Printf (ctx , "redis: re-authentication failed: %v" , err )
327
320
}
328
321
}
329
322
}
0 commit comments