redis/jedis · critical · JedisException
Could not get a resource from the pool
Error message
Could not get a resource from the pool
What it means
Pool.getResource() borrows a connection from the underlying commons-pool2 pool. JedisExceptions (e.g. connection failures) are rethrown as-is; any other Exception from borrowObject is wrapped in JedisException("Could not get a resource from the pool"). This is the classic sign that the client cannot obtain a Redis connection.
Solutions
- Check Redis availability: `redis-cli -h <host> -p <port> ping` should return PONG.
- Inspect getCause(): JedisConnectionException means connectivity; NoSuchElementException/timeout means pool exhaustion.
- Leak-check: ensure every getResource() has a matching returnResource/close (use try-with-resources on Jedis).
- Raise pool config (setMaxTotal/maxWait) if exhaustion is legitimate load.
- Verify host/port/firewall/timeout settings in JedisPool/ConnectionPoolConfig.
Example fix
// before
Jedis j = pool.getResource(); // leaked on exception paths
// after
try (Jedis j = pool.getResource()) {
j.set("k", "v");
} // auto-returns connection, prevents exhaustion Defensive patterns
Strategy: try-catch
Validate before calling
// before borrowing, verify reachability
try (Socket s = new Socket()) {
s.connect(new InetSocketAddress(host, port), 2000); // throws if Redis unreachable
} Try / catch
try (Jedis jedis = pool.getResource()) {
jedis.ping();
} catch (JedisException e) {
if (e.getCause() instanceof NoSuchElementException) {
// pool exhausted: check leaks / raise maxTotal
} else {
// connectivity issue: check host/port/network
}
throw e;
} Prevention
- Always use try-with-resources for borrowed connections.
- Monitor pool metrics (active/idle/waiting) for exhaustion and leaks.
- Size maxTotal >= concurrent threads using connections.
- Set explicit timeout configs so borrow fails fast.
When it happens
Trigger: pool.getResource() when Redis is down/unreachable, max pool capacity (blockWhenExhausted + maxWait) is exhausted, connection timeouts, or the factory makeObject fails (bad host/port, auth failure in newer paths).
Common situations: Redis not running or wrong host/port in config; pool exhausted because connections are leaked (never returned to pool); network latency/firewall blocking port 6379; too small maxTotal for thread count under load.
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
- Attempting to write to a broken connection.
- Attempting to read from a broken connection.
- Failed to create socket.
- It seems like server has closed the connection.
- Failed to read pending buffer for push messages!
AI-assisted analysis of redis/jedis@6dac31d4c2 (2026-09-08).
Data as JSON: /api/errors/9574f52a25efcd69.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/redis/clients/jedis/util/Pool.java:42
public void close() {
destroy();
}
public void destroy() {
try {
super.close();
} catch (RuntimeException e) {
throw new JedisException("Could not destroy the pool", e);
}
}
public T getResource() {
try {
return super.borrowObject();
} catch (JedisException je) {
throw je;
} catch (Exception e) {
throw new JedisException("Could not get a resource from the pool", e);
}
}
public void returnResource(final T resource) {
if (resource == null) {
return;
}
try {
super.returnObject(resource);
} catch (RuntimeException e) {
throw new JedisException("Could not return the resource to the pool", e);
}
}
public void returnBrokenResource(final T resource) {
if (resource == null) {
return;
}View on GitHub (pinned to 6dac31d4c2)