@@ -285,21 +285,22 @@ 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 )
292
- ctx = c .context (ctx )
288
+ func (c * baseClient ) newReAuthCredentialsListener (poolCn * pool.Conn ) auth.CredentialsListener {
293
289
return auth .NewReAuthCredentialsListener (
294
- c .reAuthConnection (ctx , conn ),
295
- c .onAuthenticationErr (ctx , conn ),
290
+ c .reAuthConnection (poolCn ),
291
+ c .onAuthenticationErr (poolCn ),
296
292
)
297
293
}
298
294
299
- func (c * baseClient ) reAuthConnection (ctx context. Context , cn * Conn ) func (credentials auth.Credentials ) error {
295
+ func (c * baseClient ) reAuthConnection (poolCn * pool. Conn ) func (credentials auth.Credentials ) error {
300
296
return func (credentials auth.Credentials ) error {
301
297
var err error
302
298
username , password := credentials .BasicAuth ()
299
+ ctx := context .Background ()
300
+ connPool := pool .NewSingleConnPool (c .connPool , poolCn )
301
+ // hooksMixin are intentionally empty here
302
+ cn := newConn (c .opt , connPool , nil )
303
+
303
304
if username != "" {
304
305
err = cn .AuthACL (ctx , username , password ).Err ()
305
306
} else {
@@ -308,22 +309,13 @@ func (c *baseClient) reAuthConnection(ctx context.Context, cn *Conn) func(creden
308
309
return err
309
310
}
310
311
}
311
- func (c * baseClient ) onAuthenticationErr (ctx context. Context , cn * Conn ) func (err error ) {
312
+ func (c * baseClient ) onAuthenticationErr (poolCn * pool. Conn ) func (err error ) {
312
313
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
314
if err != nil {
316
315
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
- }
316
+ c .connPool .CloseConn (poolCn )
326
317
}
318
+ internal .Logger .Printf (context .Background (), "redis: re-authentication failed: %v" , err )
327
319
}
328
320
}
329
321
}
@@ -368,7 +360,7 @@ func (c *baseClient) initConn(ctx context.Context, cn *pool.Conn) error {
368
360
username , password := "" , ""
369
361
if c .opt .StreamingCredentialsProvider != nil {
370
362
credentials , unsubscribeFromCredentialsProvider , err := c .opt .StreamingCredentialsProvider .
371
- Subscribe (c .newReAuthCredentialsListener (ctx , cn ))
363
+ Subscribe (c .newReAuthCredentialsListener (cn ))
372
364
if err != nil {
373
365
return fmt .Errorf ("failed to subscribe to streaming credentials: %w" , err )
374
366
}
0 commit comments