{"record":{"id":"9574f52a25efcd69","repo":"redis/jedis","slug":"could-not-get-a-resource-from-the-pool","errorCode":null,"errorMessage":"Could not get a resource from the pool","messagePattern":"Could not get a resource from the pool","errorType":"exception","errorClass":"JedisException","httpStatus":null,"severity":"critical","filePath":"src/main/java/redis/clients/jedis/util/Pool.java","lineNumber":42,"sourceCode":"  public void close() {\n    destroy();\n  }\n\n  public void destroy() {\n    try {\n      super.close();\n    } catch (RuntimeException e) {\n      throw new JedisException(\"Could not destroy the pool\", e);\n    }\n  }\n\n  public T getResource() {\n    try {\n      return super.borrowObject();\n    } catch (JedisException je) {\n      throw je;\n    } catch (Exception e) {\n      throw new JedisException(\"Could not get a resource from the pool\", e);\n    }\n  }\n\n  public void returnResource(final T resource) {\n    if (resource == null) {\n      return;\n    }\n    try {\n      super.returnObject(resource);\n    } catch (RuntimeException e) {\n      throw new JedisException(\"Could not return the resource to the pool\", e);\n    }\n  }\n\n  public void returnBrokenResource(final T resource) {\n    if (resource == null) {\n      return;\n    }","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/util/Pool.java#L24-L60","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\nJedis j = pool.getResource(); // leaked on exception paths\n// after\ntry (Jedis j = pool.getResource()) {\n  j.set(\"k\", \"v\");\n} // auto-returns connection, prevents exhaustion","handlingStrategy":"try-catch","validationCode":"// before borrowing, verify reachability\ntry (Socket s = new Socket()) {\n  s.connect(new InetSocketAddress(host, port), 2000); // throws if Redis unreachable\n}","typeGuard":null,"tryCatchPattern":"try (Jedis jedis = pool.getResource()) {\n  jedis.ping();\n} catch (JedisException e) {\n  if (e.getCause() instanceof NoSuchElementException) {\n    // pool exhausted: check leaks / raise maxTotal\n  } else {\n    // connectivity issue: check host/port/network\n  }\n  throw e;\n}","preventionTips":["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."],"tags":["pool","connection","exhaustion","network"],"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"}