{"record":{"id":"299c35c7942a22d8","repo":"apache/hadoop","slug":"got-wrong-length-during-writeblock-from-at","errorCode":null,"errorMessage":"Got wrong length during writeBlock({}) from {} at offset {}: {}","messagePattern":"Got wrong length during writeBlock\\((.+?)\\) from (.+?) at offset (.+?): (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockReceiver.java","lineNumber":568,"sourceCode":"   * returns the number of data bytes that the packet has.\n   */\n  private int receivePacket() throws IOException {\n    // read the next packet\n    packetReceiver.receiveNextPacket(in);\n\n    PacketHeader header = packetReceiver.getHeader();\n    long seqno = header.getSeqno();\n    LOG.debug(\"Receiving one packet for block {} seqno:{} header:{} \", block,\n        seqno, header);\n\n    // Sanity check the header\n    if (header.getOffsetInBlock() > replicaInfo.getNumBytes()) {\n      throw new IOException(\"Received an out-of-sequence packet for \" + block + \n          \"from \" + inAddr + \" at offset \" + header.getOffsetInBlock() +\n          \". Expecting packet starting at \" + replicaInfo.getNumBytes());\n    }\n    if (header.getDataLen() < 0) {\n      throw new IOException(\"Got wrong length during writeBlock(\" + block + \n                            \") from \" + inAddr + \" at offset \" + \n                            header.getOffsetInBlock() + \": \" +\n                            header.getDataLen()); \n    }\n\n    long offsetInBlock = header.getOffsetInBlock();\n    boolean lastPacketInBlock = header.isLastPacketInBlock();\n    final int len = header.getDataLen();\n    boolean syncBlock = header.getSyncBlock();\n\n    // avoid double sync'ing on close\n    if (syncBlock && lastPacketInBlock) {\n      this.syncOnClose = false;\n      // sync directory for finalize irrespective of syncOnClose config since\n      // sync is requested.\n      this.dirSyncOnFinalize = true;\n    }\n","sourceCodeStart":550,"sourceCodeEnd":586,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockReceiver.java#L550-L586","documentation":"Error \"Got wrong length during writeBlock({}) from {} at offset {}: {}\" thrown in apache/hadoop.","triggerScenarios":"The data length read from the stream during receiveBlock does not match the length advertised in the packet header at the current offset.","commonSituations":"The packet length field did not match the data actually received, typically from stream corruption or a truncated connection. Check network stability between client and DataNode.","solutions":["Verify client and DataNode versions are compatible; a malformed packet header length field usually indicates protocol mismatch or stream corruption.","Inspect the network path for truncation/corruption and check the client logs for earlier errors in the same block write."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}