redis/jedis · error · JedisException
Could not destroy the pool
Error message
Could not destroy the pool
What it means
Pool.destroy() closes the underlying commons-pool2 object pool. If close() throws a RuntimeException, it is wrapped in a JedisException with message "Could not destroy the pool". This means the pool's resources could not be released cleanly.
Solutions
- Inspect the wrapped cause (getCause()) to find the underlying pool factory failure.
- Ensure connections are returned/closed before destroying the pool.
- Guard against double-destroy with an idempotent shutdown hook (close() is already a no-op wrapper-safe path; check your own code for repeated destroy calls).
- Check network/firewall state if socket closes time out during destroy.
Example fix
// before
pool.destroy(); // may throw JedisException on flaky sockets
// after
try (Pool<Jedis> p = pool) {
// use pool
} // close() swallows-safe; or:
try { pool.destroy(); } catch (JedisException e) {
log.warn("Pool destroy failed", e.getCause());
} Defensive patterns
Strategy: try-catch
Try / catch
try {
pool.destroy();
} catch (JedisException e) {
log.warn("Pool destroy failed", e.getCause());
} Prevention
- Return all resources before destroying the pool.
- Make shutdown idempotent (guard double destroy).
- Check the cause for socket/network issues during shutdown.
When it happens
Trigger: Calling pool.destroy() (directly or via pool.close()) while the internal GenericObjectPool close fails — typically due to a blocked/aborted eviction thread, an exception from a factory destroyObject (e.g. socket close failure), or double-destroy in a broken state.
Common situations: Shutting down an application whose Redis connections are in a bad network state; calling destroy() twice concurrently; closing pools while idle-eviction is running.
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 return the broken resource to the pool
- <server status code reply>
- Could not get a resource from the pool
- Could not return the resource to the pool
- Error trying to add idle objects
AI-assisted analysis of redis/jedis@6dac31d4c2 (2026-09-08).
Data as JSON: /api/errors/673b95975ff8c017.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/redis/clients/jedis/util/Pool.java:32
public Pool(final PooledObjectFactory<T> factory, final GenericObjectPoolConfig<T> poolConfig) {
super(factory, poolConfig);
}
public Pool(final PooledObjectFactory<T> factory) {
super(factory);
}
@Override
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 {View on GitHub (pinned to 6dac31d4c2)