{"record":{"id":"b91537acf58c5bb0","repo":"redis/jedis","slug":"error-while-validating-pooled-jedis-object","errorCode":null,"errorMessage":"Error while validating pooled Jedis object.","messagePattern":"Error while validating pooled Jedis object\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/main/java/redis/clients/jedis/JedisFactory.java","lineNumber":236,"sourceCode":"\n  @Override\n  public boolean validateObject(PooledObject<Jedis> pooledJedis) {\n    final Jedis jedis = pooledJedis.getObject();\n    try {\n      boolean targetHasNotChanged = true;\n      if (jedisSocketFactory instanceof DefaultJedisSocketFactory) {\n        HostAndPort targetAddress = ((DefaultJedisSocketFactory) jedisSocketFactory)\n            .getHostAndPort();\n        HostAndPort objectAddress = jedis.getConnection().getHostAndPort();\n\n        targetHasNotChanged = targetAddress.getHost().equals(objectAddress.getHost())\n            && targetAddress.getPort() == objectAddress.getPort();\n      }\n\n      return targetHasNotChanged && jedis.getConnection().isConnected()\n          && jedis.ping().equals(\"PONG\");\n    } catch (final Exception e) {\n      logger.warn(\"Error while validating pooled Jedis object.\", e);\n      return false;\n    }\n  }\n}\n","sourceCodeStart":218,"sourceCodeEnd":241,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/JedisFactory.java#L218-L241","documentation":"JedisFactory.validateObject is the pool's pre-borrow validator for legacy Jedis objects. It checks the target server address still matches, the socket is connected, and a PING returns PONG. Any exception during these checks is caught, logged with this message, and the object is reported invalid so the pool destroys it. Like ConnectionFactory's counterpart, it is a diagnostic eviction log, not a thrown exception.","triggerScenarios":"PING on the checked-out-for-validation Jedis throws (connection reset, timeout, broken pipe); the underlying connection's socket is closed; the master address moved (sentinel/cluster failover) so targetHasNotChanged is computed against changed addresses and validation aborts with an error inside.","commonSituations":"Redis restart/failover while the JedisPool holds idle instances; idle connections reaped by firewalls/LB; Sentinel-managed master promoted elsewhere mid-validation.","solutions":["Read the cause logged alongside this warning to identify the concrete failure (timeout vs reset vs auth).","Enable test-while-idle and eviction intervals so stale instances die quietly instead of failing validation at borrow time.","With Sentinel, ensure JedisSentinelPool handles master switch (it re-creates the pool) rather than validating stale masters.","Check Redis ACL credentials are current — auth failures inside PING path also land here.","Set sane soTimeout/connectTimeout to avoid transient-latency validation failures."],"exampleFix":"// before\nJedisPool pool = new JedisPool(new JedisPoolConfig(), host); // validation only on borrow\n// after\nJedisPoolConfig pc = new JedisPoolConfig();\npc.setTestWhileIdle(true);\npc.setTestOnBorrow(true);\npc.setTimeBetweenEvictionRunsMillis(30000);\nJedisPool pool = new JedisPool(pc, host);","handlingStrategy":"retry","validationCode":"try (Jedis j = new Jedis(host, port)) {\n  if (!\"PONG\".equals(j.ping())) throw new IllegalStateException(\"Redis not healthy\");\n}","typeGuard":null,"tryCatchPattern":"try { jedis.ping(); } catch (Exception e) { pool.destroy(j); /* validator already logged */ }","preventionTips":["Enable testWhileIdle so dead objects are culled by the evictor, not at borrow time","With Sentinel, use JedisSentinelPool so master switches recreate the pool correctly","Keep soTimeout/connectTimeout generous enough for transient latency","Sync credentials with server ACL rotations"],"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"}