{"record":{"id":"ad5ca675e631c498","repo":"redis/jedis","slug":"failed-to-evict-connections-from-pool","errorCode":null,"errorMessage":"Failed to evict connections from pool","messagePattern":"Failed to evict connections from pool","errorType":"exception","errorClass":"JedisException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/ConnectionPool.java","lineNumber":188,"sourceCode":"  protected void attachAuthenticationListener(AuthXManager authXManager) {\n    this.authXManager = authXManager;\n    if (authXManager != null) {\n      authXManager.addPostAuthenticationHook(this::postAuthentication);\n    }\n  }\n\n  protected void detachAuthenticationListener() {\n    if (authXManager != null) {\n      authXManager.removePostAuthenticationHook(this::postAuthentication);\n    }\n  }\n\n  private void postAuthentication(Token token) {\n    try {\n      // this is to trigger validations on each connection via ConnectionFactory\n      evict();\n    } catch (Exception e) {\n      throw new JedisException(\"Failed to evict connections from pool\", e);\n    }\n  }\n}\n","sourceCodeStart":170,"sourceCodeEnd":192,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/ConnectionPool.java#L170-L192","documentation":"ConnectionPool.postAuthentication() calls evict() to force every idle connection to be revalidated via ConnectionFactory after a token-based re-authentication, and wraps any failure in JedisException('Failed to evict connections from pool') with the original cause attached.","triggerScenarios":"Token/credential rotation on a pooled client where pool.evict() throws — e.g. the underlying JedisSocketFactory fails to create/validate sockets during eviction, or connections fail their post-eviction validation against the server.","commonSituations":"ACL/token-based auth with short-lived credentials where the server was restarted or unreachable during rotation; network blips while idle connections are being validated; broken custom ConnectionFactory/SocketFactory implementations.","solutions":["Inspect the wrapped cause (e.getCause()) — it names the actual eviction/validation failure","Verify the Redis endpoint is reachable and credentials are valid at rotation time","Check the custom ConnectionFactory/socketFactory validation logic if one is configured","Retry the rotation/pool refresh once connectivity is restored"],"exampleFix":"// before\npool.setToken(token); // JedisException: Failed to evict connections from pool\n// after\ntry {\n  pool.setToken(token);\n} catch (JedisException e) {\n  logger.error(\"Token rotation failed during pool eviction\", e.getCause());\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":"// pre-check connectivity before token rotation\ntry (Jedis j = new Jedis(hostAndPort, cfg)) { j.ping(); }","typeGuard":null,"tryCatchPattern":"try {\n  pool.setToken(token);\n} catch (JedisException e) {\n  Throwable cause = e.getCause();\n  log.error(\"Pool eviction after auth failed: {}\", cause == null ? e : cause.getMessage());\n}","preventionTips":["Keep the Redis endpoint reachable during token rotation windows","Inspect getCause() — the real failure (socket/valication error) is wrapped","Test custom ConnectionFactory/socketFactory validation logic under pool eviction","Schedule rotations with retry/backoff to tolerate transient network issues"],"tags":["java","jedis","connection-pool","eviction","authentication"],"backgroundTag":"connection-refused","analyzedSha":"6dac31d4c224fb3257c216f3985340c6f500cdcb","analyzedAt":"2026-09-08T04:55:01.204Z","contentChangedAt":"2026-09-08T04:55:01.204Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}