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
- 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.
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
- Warm the pool only after confirming Redis is ready.
- Warm in smaller batches with backoff.
- Validate TLS/auth config before eager connection creation.
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
- Could not get a resource from the pool
- Attempting to write to a broken connection.
- Attempting to read from a broken connection.
- Failed to create socket.
- The connection to ' ' failed ssl/tls hostname verification.
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)