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
- Inspect the wrapped IOException cause for the real error (SSL, EMFILE, connection reset).
- Check TLS/SSL configuration (truststore, SNI, certificate) when connecting to a TLS-enabled Redis.
- Verify file-descriptor limits (ulimit) if errors correlate with load.
- 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
- Validate TLS config (truststore, certificates) before deployment
- Check ulimit/fd limits on hosts with many connections
- Test network path through proxies/LBs for post-connect resets
- Use the builder's connection validation at startup rather than failing lazily
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
- Failed to create socket.
- The connection to ' ' failed ssl/tls hostname verification.
- Unexpected message
- Initialization failed due to initialization policy
- Initialization failed due to initialization policy
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)