{"record":{"id":"c7566e028e356187","repo":"redis/jedis","slug":"failed-to-create-connection","errorCode":null,"errorMessage":"Failed to create connection!","messagePattern":"Failed to create connection!","errorType":"exception","errorClass":"JedisConnectionException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/mcf/TrackingConnectionPool.java","lineNumber":43,"sourceCode":"    private volatile boolean failFast = false;\n    private final Set<Connection> factoryTrackedObjects = ConcurrentHashMap.newKeySet();\n\n    private static class FailFastFactoryBuilder extends ConnectionFactory.Builder {\n\n      @Override\n      protected ConnectionFactory create() {\n        return new FailFastConnectionFactory(this);\n      }\n    }\n\n    public FailFastConnectionFactory(Builder factoryBuilder) {\n      super(factoryBuilder);\n    }\n\n    @Override\n    public PooledObject<Connection> makeObject() throws Exception {\n      if (failFast) {\n        throw new JedisConnectionException(\"Failed to create connection!\");\n      }\n      try {\n        PooledObject<Connection> object = super.makeObject();\n        // this can make a marginal improvement on fast failover duration!\n        if (failFast) {\n          object.getObject().close();\n          throw new JedisConnectionException(\"Failed to create connection!\");\n        }\n        return object;\n      } catch (JedisConnectionException e) {\n        throw e;\n      } catch (Exception e) {\n        throw new JedisConnectionException(e);\n      }\n    }\n\n    @Override\n    protected void initialize(Connection conn) {","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/mcf/TrackingConnectionPool.java#L25-L61","documentation":"TrackingConnectionPool.makeObject (used by multi-db/failover pools) supports a failFast mode: when failFast is already marked true, object creation is refused immediately with JedisConnectionException before any socket is attempted. This short-circuits connection attempts against an endpoint known (or suspected) to be down so failover happens faster.","triggerScenarios":"A connection is requested from a TrackingConnectionPool whose failFast flag has been set (e.g. by the failover/status tracker after failed health checks or a forceDisconnect), and makeObject is invoked — the pool refuses to build any new connection while fail-fast is active.","commonSituations":"An endpoint was marked down by the health check manager and the application still routes commands to it; a race where the failFast flag flips between the check and the request; clients pinned to a specific database endpoint that has just been declared unhealthy.","solutions":["Route traffic to a healthy endpoint: let the multi-db failover logic pick another database instead of retrying the same pool.","Check why failFast was set — inspect health check status/events for the endpoint and wait for it to recover.","Catch JedisConnectionException and retry on an alternate endpoint/client.","If the endpoint is actually healthy, fix the health check configuration (probe address, interval, thresholds) that wrongly marked it down."],"exampleFix":"// before\nConnection c = failingPool.getResource(); // pool failFast => throws\n// after\nif (healthStatusManager.isActive(endpoint)) {\n  Connection c = failingPool.getResource();\n} else {\n  Connection c = healthyClientPool.getResource(); // fail over to alternate db\n}","handlingStrategy":"fallback","validationCode":"if (pool.isFailFastActive() || !healthStatusManager.isActive(endpoint)) {\n  useAlternateEndpoint();\n}","typeGuard":null,"tryCatchPattern":"try {\n  conn = pool.getResource();\n} catch (JedisConnectionException e) {\n  conn = alternateDbClient.getResource();\n}","preventionTips":["Route via the multi-db client's failover logic instead of pinning to one pool.","Keep health check configs accurate so failFast clears when endpoints recover.","Retry with backoff on an alternate endpoint, never hot-loop the same failing pool."],"tags":["connection-pool","fail-fast","multi-db","failover"],"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"}