{"record":{"id":"a3b1e27439b23963","repo":"redis/jedis","slug":"error-while-validating-pooled-connection-object","errorCode":null,"errorMessage":"Error while validating pooled Connection object.","messagePattern":"Error while validating pooled Connection object\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/main/java/redis/clients/jedis/ConnectionFactory.java","lineNumber":238,"sourceCode":"  }\n\n  @Override\n  public boolean validateObject(PooledObject<Connection> pooledConnection) {\n    final Connection jedis = pooledConnection.getObject();\n    try {\n      // check HostAndPort ??\n      if (!jedis.isConnected()) {\n        return false;\n      }\n      if (jedis.isRetired()) {\n        return false; // marked by a maintenance marking pass -> recycle\n      }\n      reAuthenticate(jedis);\n      // Re-check after the ping: its read may consume a buffered MOVING push whose inline\n      // marking pass marks this connection.\n      return jedis.ping() && !jedis.isRetired();\n    } catch (final Exception e) {\n      logger.warn(\"Error while validating pooled Connection object.\", e);\n      return false;\n    }\n  }\n\n  private void reAuthenticate(Connection jedis) throws Exception {\n    try {\n      String result = jedis.reAuthenticate();\n      if (result != null && !result.equals(\"OK\")) {\n        String msg = \"Re-authentication failed with server response: \" + result;\n        Exception failedAuth = new JedisAuthenticationException(msg);\n        logger.error(failedAuth.getMessage(), failedAuth);\n        authXEventListener.onConnectionAuthenticationError(failedAuth);\n        return;\n      }\n    } catch (Exception e) {\n      logger.error(\"Error while re-authenticating connection\", e);\n      authXEventListener.onConnectionAuthenticationError(e);\n      throw e;","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/ConnectionFactory.java#L220-L256","documentation":"This warning is logged by ConnectionFactory.validateObject when a pooled connection fails its periodic health check. The pool calls validateObject before handing a connection to the caller; any exception during re-authentication or PING (socket closed, timeout, protocol error) is swallowed and the connection is reported invalid so the pool destroys it. It is diagnostic, not fatal — the pool simply evicts the bad connection.","triggerScenarios":"PING to Redis times out or throws (server restarted, network drop, connection already closed); reAuthenticate() fails because the password/username changed or ACLs were updated; the connection was marked retired by a MOVING maintenance push after the ping.","commonSituations":"Redis server restart or failover while a pool holds idle connections; firewall/NAT silently dropping idle TCP connections (validate then fails on first use after idle); credentials rotated in Redis ACL without updating the client config.","solutions":["Check Redis server logs and network stability between client and server; the underlying exception printed with this warning names the root cause.","Enable pool test-while-idle / eviction settings so dead connections are culled before validation-time failures.","If re-authentication failures, confirm username/password in JedisClientConfig match current Redis ACLs.","Upgrade or tune socket timeout / connect timeout so transient latency does not fail PING.","If MOVING/retired events are involved, ensure maintenance-event handling is enabled so retired connections are replaced cleanly."],"exampleFix":"// before\nJedisPool pool = new JedisPool(config, host); // defaults: no idle testing\n// after\nGenericObjectPoolConfig<Jedis> pc = new GenericObjectPoolConfig<>();\npc.setTestWhileIdle(true);\npc.setTimeBetweenEvictionRunsMillis(30000);\npc.setMinEvictableIdleTimeMillis(60000);\nJedisPool pool = new JedisPool(pc, config, host, port);","handlingStrategy":"retry","validationCode":"try (Jedis probe = new Jedis(host, port)) {\n  probe.ping(); // throws quickly if Redis unreachable before pool use\n}","typeGuard":null,"tryCatchPattern":"try { jedis.ping(); } catch (JedisConnectionException e) { logger.warn(\"connection dead, will be evicted\", e); pool.clear(); }","preventionTips":["Enable testWhileIdle with a timeBetweenEvictionRunsMillis below any firewall idle timeout","Keep soTimeout above the slowest command's worst-case latency","Rotate client credentials in sync with Redis ACL changes","Monitor Redis restarts/failovers so validation warnings correlate with known events"],"tags":["redis","connection-pool","health-check","network"],"backgroundTag":"network-request-failed","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"}