redis/jedis · error · JedisException

Error trying to add idle objects

Error message

Error trying to add idle objects

What it means

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").

Solutions

  1. Verify Redis is reachable before warming: `redis-cli ping`.
  2. Reduce count and retry with backoff so a transient outage doesn't fail the whole warm-up.
  3. Check the wrapped cause for the exact connection error (refused/timeout/auth).
  4. Validate TLS/auth settings if the first connection always fails.

Example fix

// before
pool.addObjects(50); // fails hard if Redis is momentarily down
// after
for (int attempt = 0; attempt < 5; attempt++) {
  try { pool.addObjects(50); break; }
  catch (JedisException e) { Thread.sleep(1000L * (attempt + 1)); }
}
Defensive patterns

Strategy: retry

Validate before calling

// reachability check before addObjects
try (Jedis j = pool.getResource()) { j.ping(); }

Try / catch

for (int i = 0; i < 3; i++) {
  try { pool.addObjects(n); break; }
  catch (JedisException e) { backoff(i); }
}

Prevention

When it happens

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

Common situations: Warming the pool at startup before Redis is ready (container orchestration race); TLS misconfiguration; adding objects after pool destruction.

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/b0e9ed8026e85ba6. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/redis/clients/jedis/util/Pool.java:75

  public void returnBrokenResource(final T resource) {
    if (resource == null) {
      return;
    }
    try {
      super.invalidateObject(resource);
    } catch (Exception e) {
      throw new JedisException("Could not return the broken resource to the pool", e);
    }
  }

  @Override
  public void addObjects(int count) {
    try {
      for (int i = 0; i < count; i++) {
        addObject();
      }
    } catch (Exception e) {
      throw new JedisException("Error trying to add idle objects", e);
    }
  }
}

View on GitHub (pinned to 6dac31d4c2)