{"record":{"id":"21085ee413fe0779","repo":"redis/jedis","slug":"it-seems-like-server-has-closed-the-connection-21085e","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":"error","filePath":"src/main/java/redis/clients/jedis/util/RedisInputStream.java","lineNumber":96,"sourceCode":"\n      byte b = buf[count++];\n      if (b == '\\r') {\n        ensureFill(); // Must be one more byte\n\n        byte c = buf[count++];\n        if (c == '\\n') {\n          break;\n        }\n        sb.append((char) b);\n        sb.append((char) c);\n      } else {\n        sb.append((char) b);\n      }\n    }\n\n    final String reply = sb.toString();\n    if (reply.isEmpty()) {\n      throw new JedisConnectionException(\"It seems like server has closed the connection.\");\n    }\n\n    return reply;\n  }\n\n  public byte[] readLineBytes() {\n\n    /*\n     * This operation should only require one fill. In that typical case we optimize allocation and\n     * copy of the byte array. In the edge case where more than one fill is required then we take a\n     * slower path and expand a byte array output stream as is necessary.\n     */\n\n    ensureFill();\n\n    int pos = count;\n    final byte[] buf = this.buf;\n    while (true) {","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/util/RedisInputStream.java#L78-L114","documentation":"RedisInputStream.readLine builds a reply line byte by byte; if the very first byte available is an immediate end-of-stream producing an empty line, the server has closed the connection without sending any reply. Jedis throws JedisConnectionException because no response exists to parse.","triggerScenarios":"Thrown from the public readLine (used by message, readErrorLineIfPossible, readDoubleCrLf, readBigIntegerCrLf) when the accumulated line is empty because the underlying stream hit EOF immediately (ensureFill saw limit == -1).","commonSituations":"Redis server restarted or crashed between request and reply; server-side client timeout (timeout config) killing idle connections; a load balancer idling out the TCP connection; network partition dropping the socket.","solutions":["Discard and reopen the connection; retry the command on a fresh connection (idempotent commands only).","Enable Jedis pool testOnBorrow/testWhileIdle and set pool eviction settings so dead connections are pruned.","Match client socket timeout below the server's `timeout` setting and any LB idle timeout; send periodic PINGs or enable TCP keepalive.","Check Redis server logs (and `CLIENT LIST`) for kills or restarts around the failure time."],"exampleFix":"// before\nJedisPool pool = new JedisPool(config, host);\n// idle connections die silently\n// after\nJedisPool pool = new JedisPoolBuilder()\n  .connectionConfig(JedisClientConfig.builder()\n      .timeoutMillis(30000)\n      .blockingSocketTimeoutMillis(0).build())\n  .poolConfig(new GenericObjectPoolConfig.Builder()\n      .testWhileIdle(true)\n      .timeBetweenEvictionRunsMillis(30000).build())\n  .hostAndPort(host, port).build();","handlingStrategy":"retry","validationCode":"// before executing: ensure pool validates connections\nif (!jedis.isConnected()) { jedis = pool.getResource(); }","typeGuard":null,"tryCatchPattern":"try {\n  return jedis.get(key);\n} catch (JedisConnectionException e) {\n  // server closed connection; retry once on a fresh resource\n  try (Jedis fresh = pool.getResource()) {\n    return fresh.get(key);\n  }\n}","preventionTips":["Enable testWhileIdle/testOnBorrow in the pool config.","Set client socket timeout below server `timeout` and LB idle timeout.","Send keepalive PINGs for long idle periods; enable TCP keepalive.","Retry only idempotent commands."],"tags":["connection","network","eof","redis"],"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"}