redis/jedis · error · JedisConnectionException

Failed to create input/output stream

Error message

Failed to create input/output stream

What it means

During Connection.connect(), after the TCP socket is opened the client wraps it in input/output streams (and reader/writer). An IOException there means the connection could not be fully established despite the socket succeeding; it is marked broken and rethrown as JedisConnectionException.

Solutions

  1. Inspect the wrapped IOException cause for the real error (SSL, EMFILE, connection reset).
  2. Check TLS/SSL configuration (truststore, SNI, certificate) when connecting to a TLS-enabled Redis.
  3. Verify file-descriptor limits (ulimit) if errors correlate with load.
  4. Test network path (proxy/LB/firewall) for immediate post-connect resets.
Defensive patterns

Strategy: try-catch

Validate before calling

// preflight: TLS reachability of the endpoint
try (Socket s = sslSocketFactory.createSocket(host, port)) { s.startHandshake(); }

Try / catch

try {
  RedisClient.create(...).build();
} catch (JedisConnectionException e) {
  Throwable root = e.getCause(); // inspect the wrapped IOException/SSL error
  throw new ConfigException("Cannot establish streams to " + host + ":" + port, root);
}

Prevention

When it happens

Trigger: connect() fails creating BufferedInputStream/BufferedOutputStream or the RESP reader/writer: socket closed concurrently, SSL handshake-derived stream failure, or OS-level socket error immediately after connect.

Common situations: TLS misconfiguration (wrong truststore causing stream setup failure downstream), proxy or LB resetting connections immediately after accept, resource exhaustion (too many open files), half-open sockets in containerized environments.

Related errors


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

Appendix: source

Thrown at src/main/java/redis/clients/jedis/Connection.java:591

          appliedSoTimeout = -1;
          applyCurrentTimeout();
        } else {
          defaultTimeoutSource.setDefaults(socket.getSoTimeout(), getBlockingSoTimeout());
        }


        outputStream = new RedisOutputStream(socket.getOutputStream());
        inputStream = new RedisInputStream(socket.getInputStream());

        himportState.reset(); // a fresh socket lost any server-side HIMPORT fieldsets

      } catch (JedisConnectionException jce) {

        throw markBroken(jce);

      } catch (IOException ioe) {

        throw markBroken(new JedisConnectionException("Failed to create input/output stream", ioe));

      } catch (RuntimeException ex) {

        throw markBroken(ex);

      } catch (Error err) {

        throw markBroken(err);

      } finally {

        if (broken) {
          IOUtils.closeQuietly(socket);
        }
      }
    }
  }

View on GitHub (pinned to 6dac31d4c2)