{"record":{"id":"fec391f1806ef4a6","repo":"redis/jedis","slug":"failed-to-check-buffer-on-connection","errorCode":null,"errorMessage":"Failed to check buffer on connection.","messagePattern":"Failed to check buffer on connection\\.","errorType":"exception","errorClass":"JedisConnectionException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/Connection.java","lineNumber":809,"sourceCode":"      // leave the stream position indeterminate.\n      throw markBroken(exc);\n    } catch (Error err) {\n      throw markBroken(err);\n    }\n  }\n\n  protected void readPushesWithCheckingBroken() {\n    if (broken) {\n      throw new JedisConnectionException(\"Attempting to read from a broken connection.\", brokenCause);\n    }\n\n    try {\n      applyCurrentTimeout();\n      if (inputStream.available() > 0) {\n        protocolReadPushes(inputStream, pushConsumers);\n      }\n    } catch (IOException e) {\n      throw markBroken(new JedisConnectionException(\"Failed to check buffer on connection.\", e));\n    } catch (RuntimeException exc) {\n      throw markBroken(exc);\n    } catch (Error err) {\n      throw markBroken(err);\n    }\n  }\n\n  public List<Object> getMany(final int count) {\n    flush();\n    final List<Object> responses = new ArrayList<>(count);\n    for (int i = 0; i < count; i++) {\n      try {\n        responses.add(readProtocolWithCheckingBroken());\n      } catch (JedisDataException e) {\n        responses.add(e);\n      }\n    }\n    return responses;","sourceCodeStart":791,"sourceCodeEnd":827,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/Connection.java#L791-L827","documentation":"This connection check probes whether buffered bytes are pending on the socket (inputStream.available()) and consumes any pushed messages. An IOException during this check indicates the socket is dead or unreadable, so the connection is marked broken and a JedisConnectionException is thrown.","triggerScenarios":"Checking the input buffer on a connection whose socket was closed/reset by the peer (server restart, failover, idle timeout, network partition) — invoked from the public Connection health-check path.","commonSituations":"Redis server restarted between commands; sentinel/cluster failover closed old connections; NAT or LB silently dropping idle TCP connections; long-lived pooled connections that went stale.","solutions":["Treat the exception as a stale-connection signal: drop the connection and retry the operation on a new one.","Enable connection pool eviction/test-on-borrow style health checks (or keepalive) to prune stale sockets.","Configure TCP keepalive and reasonable socket timeouts to detect dead peers faster.","Ensure RESP3 push handling is set up correctly if this fires during push processing."],"exampleFix":"// before\nJedis j = pool.getResource(); // stale pooled conn may throw here\n// after\njedisPool with testWhileIdle/minEvictableIdleTime configured; catch JedisConnectionException and retry once with a fresh resource","handlingStrategy":"retry","validationCode":"// prune stale pooled connections\ntry (Jedis j = pool.getResource()) { j.ping(); } // before critical work","typeGuard":null,"tryCatchPattern":"try {\n  return jedis.get(key);\n} catch (JedisConnectionException e) {\n  return freshJedis().get(key); // one retry on a new connection\n}","preventionTips":["Enable pool idle-eviction and periodic health checks (ping)","Set TCP keepalive and sane SO_TIMEOUT values","Prefer fresh connections after server restarts/failovers","Monitor server-side 'client killed' and connection churn metrics"],"tags":["redis","socket","stale-connection","health-check"],"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"}