{"record":{"id":"b0e9ed8026e85ba6","repo":"redis/jedis","slug":"error-trying-to-add-idle-objects","errorCode":null,"errorMessage":"Error trying to add idle objects","messagePattern":"Error trying to add idle objects","errorType":"exception","errorClass":"JedisException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/util/Pool.java","lineNumber":75,"sourceCode":"  public void returnBrokenResource(final T resource) {\n    if (resource == null) {\n      return;\n    }\n    try {\n      super.invalidateObject(resource);\n    } catch (Exception e) {\n      throw new JedisException(\"Could not return the broken resource to the pool\", e);\n    }\n  }\n\n  @Override\n  public void addObjects(int count) {\n    try {\n      for (int i = 0; i < count; i++) {\n        addObject();\n      }\n    } catch (Exception e) {\n      throw new JedisException(\"Error trying to add idle objects\", e);\n    }\n  }\n}\n","sourceCodeStart":57,"sourceCodeEnd":79,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/util/Pool.java#L57-L79","documentation":"Pool.addObjects(count) eagerly creates `count` idle connections by calling addObject() count times. Any Exception during those additions (typically connection failures while opening new sockets) is wrapped in JedisException(\"Error trying to add idle objects\").","triggerScenarios":"pool.addObjects(n) when Redis is unreachable, refuses connections, or times out while creating the new connections; also factory makeObject failures from bad auth/TLS config.","commonSituations":"Warming the pool at startup before Redis is ready (container orchestration race); TLS misconfiguration; adding objects after pool destruction.","solutions":["Verify Redis is reachable before warming: `redis-cli ping`.","Reduce count and retry with backoff so a transient outage doesn't fail the whole warm-up.","Check the wrapped cause for the exact connection error (refused/timeout/auth).","Validate TLS/auth settings if the first connection always fails."],"exampleFix":"// before\npool.addObjects(50); // fails hard if Redis is momentarily down\n// after\nfor (int attempt = 0; attempt < 5; attempt++) {\n  try { pool.addObjects(50); break; }\n  catch (JedisException e) { Thread.sleep(1000L * (attempt + 1)); }\n}","handlingStrategy":"retry","validationCode":"// reachability check before addObjects\ntry (Jedis j = pool.getResource()) { j.ping(); }","typeGuard":null,"tryCatchPattern":"for (int i = 0; i < 3; i++) {\n  try { pool.addObjects(n); break; }\n  catch (JedisException e) { backoff(i); }\n}","preventionTips":["Warm the pool only after confirming Redis is ready.","Warm in smaller batches with backoff.","Validate TLS/auth config before eager connection creation."],"tags":["pool","warmup","connection"],"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"}