{"record":{"id":"e791f1fe5d031628","repo":"apache/hadoop","slug":"unexpected-eof-while-trying-to-read-response-from","errorCode":null,"errorMessage":"Unexpected EOF while trying to read response from server","messagePattern":"Unexpected EOF while trying to read response from server","errorType":"exception","errorClass":"EOFException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocolPB/PBHelperClient.java","lineNumber":532,"sourceCode":"\n  public static List<StorageTypeProto> convertStorageTypes(\n      StorageType[] types, int startIdx) {\n    if (types == null) {\n      return null;\n    }\n    final List<StorageTypeProto> protos = new ArrayList<>(\n        types.length);\n    for (int i = startIdx; i < types.length; ++i) {\n      protos.add(convertStorageType(types[i]));\n    }\n    return protos;\n  }\n\n  public static InputStream vintPrefixed(final InputStream input)\n      throws IOException {\n    final int firstByte = input.read();\n    if (firstByte == -1) {\n      throw new EOFException(\n          \"Unexpected EOF while trying to read response from server\");\n    }\n\n    int size = CodedInputStream.readRawVarint32(firstByte, input);\n    assert size >= 0;\n    return new LimitInputStream(input, size);\n  }\n\n  public static CipherOption convert(HdfsProtos.CipherOptionProto proto) {\n    if (proto != null) {\n      CipherSuite suite = null;\n      if (proto.getSuite() != null) {\n        suite = convert(proto.getSuite());\n      }\n      byte[] inKey = null;\n      if (proto.getInKey() != null) {\n        inKey = proto.getInKey().toByteArray();\n      }","sourceCodeStart":514,"sourceCodeEnd":550,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocolPB/PBHelperClient.java#L514-L550","documentation":"PBHelperClient.vintPrefixed reads the varint length prefix that frames protobuf responses (inotify getEditsFromTxid replies, short-circuit SHM responses, encryption negotiation responses). A first read() returning -1 means the server closed the connection without sending a single byte - the response never arrived, so an EOFException is thrown.","triggerScenarios":"DFSInotifyEventInputStream polls getEditsFromTxid against a NameNode that died or restarted mid-poll; a DataNode closes its domain socket before answering requestShortCircuitShm; the peer drops the connection during encryption negotiation.","commonSituations":"NN/DN restart or OOM kill while a client waits on a long-poll; idle connections reaped by a firewall; inotify tailers that outlive a NameNode failover.","solutions":["Check whether the server process (NN/DN) is alive and inspect its logs for a crash or restart","Catch EOFException, re-create the client/stream and retry from the last seen txid (inotify) or the previous request","Review server-side timeouts and any network middleboxes that kill idle connections"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"long lastSeenTxid = ...; // checkpoint\ntry {\n  batches = inotifyFetch(lastSeenTxid);\n} catch (EOFException e) {\n  // server closed before replying: re-create the stream, refetch from checkpoint\n  stream = recreateInotifyStream();\n  batches = inotifyFetch(lastSeenTxid);\n}","preventionTips":["Persist lastSeenTxid so inotify consumers resume after NN restarts","Treat EOF on any vint-framed HDFS response as 'peer gone', not data corruption","Health-check long-lived connections before large transfers"],"tags":["hdfs","eof","network","inotify","protobuf-framing"],"backgroundTag":"premature-connection-close","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}