redis/jedis · error · JedisException

Failed to evict connections from pool

Error message

Failed to evict connections from pool

What it means

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.

Solutions

  1. Inspect the wrapped cause (e.getCause()) — it names the actual eviction/validation failure
  2. Verify the Redis endpoint is reachable and credentials are valid at rotation time
  3. Check the custom ConnectionFactory/socketFactory validation logic if one is configured
  4. Retry the rotation/pool refresh once connectivity is restored

Example fix

// before
pool.setToken(token); // JedisException: Failed to evict connections from pool
// after
try {
  pool.setToken(token);
} catch (JedisException e) {
  logger.error("Token rotation failed during pool eviction", e.getCause());
  throw e;
}
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-check connectivity before token rotation
try (Jedis j = new Jedis(hostAndPort, cfg)) { j.ping(); }

Try / catch

try {
  pool.setToken(token);
} catch (JedisException e) {
  Throwable cause = e.getCause();
  log.error("Pool eviction after auth failed: {}", cause == null ? e : cause.getMessage());
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: ECONNREFUSED and "connection refused" / "could not connect to server" errors: what they mean and how to fix them — this error's family across 44 libraries.

Related errors


AI-assisted analysis of redis/jedis@6dac31d4c2 (2026-09-08). Data as JSON: /api/errors/ad5ca675e631c498. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/redis/clients/jedis/ConnectionPool.java:188

  protected void attachAuthenticationListener(AuthXManager authXManager) {
    this.authXManager = authXManager;
    if (authXManager != null) {
      authXManager.addPostAuthenticationHook(this::postAuthentication);
    }
  }

  protected void detachAuthenticationListener() {
    if (authXManager != null) {
      authXManager.removePostAuthenticationHook(this::postAuthentication);
    }
  }

  private void postAuthentication(Token token) {
    try {
      // this is to trigger validations on each connection via ConnectionFactory
      evict();
    } catch (Exception e) {
      throw new JedisException("Failed to evict connections from pool", e);
    }
  }
}

View on GitHub (pinned to 6dac31d4c2)