redis/jedis · error · JedisConnectionException

Failed to create connection!

Error message

Failed to create connection!

What it means

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.

Solutions

  1. Route traffic to a healthy endpoint: let the multi-db failover logic pick another database instead of retrying the same pool.
  2. Check why failFast was set — inspect health check status/events for the endpoint and wait for it to recover.
  3. Catch JedisConnectionException and retry on an alternate endpoint/client.
  4. If the endpoint is actually healthy, fix the health check configuration (probe address, interval, thresholds) that wrongly marked it down.

Example fix

// before
Connection c = failingPool.getResource(); // pool failFast => throws
// after
if (healthStatusManager.isActive(endpoint)) {
  Connection c = failingPool.getResource();
} else {
  Connection c = healthyClientPool.getResource(); // fail over to alternate db
}
Defensive patterns

Strategy: fallback

Validate before calling

if (pool.isFailFastActive() || !healthStatusManager.isActive(endpoint)) {
  useAlternateEndpoint();
}

Try / catch

try {
  conn = pool.getResource();
} catch (JedisConnectionException e) {
  conn = alternateDbClient.getResource();
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

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


AI-assisted analysis of redis/jedis@6dac31d4c2 (2026-09-08). Data as JSON: /api/errors/c7566e028e356187. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/redis/clients/jedis/mcf/TrackingConnectionPool.java:43

    private volatile boolean failFast = false;
    private final Set<Connection> factoryTrackedObjects = ConcurrentHashMap.newKeySet();

    private static class FailFastFactoryBuilder extends ConnectionFactory.Builder {

      @Override
      protected ConnectionFactory create() {
        return new FailFastConnectionFactory(this);
      }
    }

    public FailFastConnectionFactory(Builder factoryBuilder) {
      super(factoryBuilder);
    }

    @Override
    public PooledObject<Connection> makeObject() throws Exception {
      if (failFast) {
        throw new JedisConnectionException("Failed to create connection!");
      }
      try {
        PooledObject<Connection> object = super.makeObject();
        // this can make a marginal improvement on fast failover duration!
        if (failFast) {
          object.getObject().close();
          throw new JedisConnectionException("Failed to create connection!");
        }
        return object;
      } catch (JedisConnectionException e) {
        throw e;
      } catch (Exception e) {
        throw new JedisConnectionException(e);
      }
    }

    @Override
    protected void initialize(Connection conn) {

View on GitHub (pinned to 6dac31d4c2)