{"record":{"id":"bcf1a11b467e0189","repo":"redis/jedis","slug":"it-seems-like-server-has-closed-the-connection","errorCode":null,"errorMessage":"It seems like server has closed the connection.","messagePattern":"It seems like server has closed the connection\\.","errorType":"exception","errorClass":"JedisConnectionException","httpStatus":null,"severity":"critical","filePath":"src/main/java/redis/clients/jedis/Protocol.java","lineNumber":214,"sourceCode":"\n    if (len < skipBytes) {\n      throw new JedisConnectionException(\n          \"Bulk reply length \" + len + \" is less than expected \" + skipBytes);\n    }\n\n    // Skip the prefix bytes\n    for (int i = 0; i < skipBytes; i++) {\n      is.readByte();\n    }\n\n    // Read the remaining data\n    final int dataLen = len - skipBytes;\n    final byte[] read = new byte[dataLen];\n    int offset = 0;\n    while (offset < dataLen) {\n      final int size = is.read(read, offset, (dataLen - offset));\n      if (size == -1) {\n        throw new JedisConnectionException(\"It seems like server has closed the connection.\");\n      }\n      offset += size;\n    }\n\n    // read 2 more bytes for the command delimiter\n    is.readByte();\n    is.readByte();\n\n    return read;\n  }\n\n  /**\n   * Process a RESP3 verbatim string reply.\n   * Verbatim strings have format: =&lt;length&gt;\\r\\n&lt;format&gt;:&lt;data&gt;\\r\\n\n   * where &lt;format&gt; is a 3-character encoding hint (e.g., \"txt\" or \"mkd\").\n   * This method strips the 4-byte prefix (&lt;format&gt;:) and returns only the actual data.\n   */\n  private static byte[] processVerbatimStringReply(final RedisInputStream is) {","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/Protocol.java#L196-L232","documentation":"While reading a bulk reply payload, the underlying stream returned EOF (-1) before the full declared length was read, so Jedis throws JedisConnectionException \"It seems like server has closed the connection.\" The server (or network) dropped the connection mid-reply.","triggerScenarios":"Server closing the socket while a large bulk reply is in flight: server-side timeout, redis restart/OOM-kill, LB idle timeout, or a proxy cutting long transfers.","commonSituations":"Reading very large values (big GETs) through load balancers with short idle timeouts, client connections idle then reused after server timeout (matched by server-side close), or Redis crashing during a blocking command.","solutions":["Retry the command on a fresh connection (enable retryable executor / retry settings).","Enable connection validation and shorter client keep-alive so dead connections are detected before reuse.","Increase LB/proxy idle timeouts or enable TCP keepalive on the client side.","Check server logs for restarts/OOM and reduce value sizes or use streaming where possible."],"exampleFix":"// before\nConnectionPoolConfig pcfg = new ConnectionPoolConfig();\nJedisPool pool = new JedisPool(pcfg, host, port);\n\n// after\nConnectionPoolConfig pcfg = new ConnectionPoolConfig();\npcfg.setTestWhileIdle(true);\npcfg.setMinEvictableIdleTimeMillis(60000);\npcfg.setTimeBetweenEvictionRunsMillis(30000); // evict connections the server may have closed\nJedisPool pool = new JedisPool(pcfg, host, port);","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  return jedis.get(key);\n} catch (JedisConnectionException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"closed the connection\")) {\n    return retryOnFreshResource(key); // server dropped mid-reply; retry once on a new connection\n  }\n  throw e;\n}","preventionTips":["Enable pool eviction with testWhileIdle to drop server-dead connections.","Set TCP keepalive / client timeouts below LB idle timeouts.","Watch server logs for restarts, OOM kills, and timeout configurations.","Avoid extremely large values that hold connections open for long reads."],"tags":["network","connection","eof","server-closed-connection"],"backgroundTag":"broken-pipe","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"}