{"record":{"id":"a224fe4de40e7823","repo":"apache/hadoop","slug":"expected-checksum-is-s-while-actual-checksum-is","errorCode":null,"errorMessage":"Expected checksum is %s while actual checksum is %s","messagePattern":"Expected checksum is (.+?) while actual checksum is (.+?)","errorType":"exception","errorClass":"ChecksumMismatchException","httpStatus":null,"severity":"critical","filePath":"hadoop-cloud-storage-project/hadoop-tos/src/main/java/org/apache/hadoop/fs/tosfs/object/ObjectContent.java","lineNumber":43,"sourceCode":"import java.util.Arrays;\n\npublic class ObjectContent {\n  private final byte[] checksum;\n  private final InputStream stream;\n\n  public ObjectContent(byte[] checksum, InputStream stream) {\n    this.checksum = checksum;\n    this.stream = stream;\n  }\n\n  public InputStream stream() {\n    return stream;\n  }\n\n  public InputStream verifiedStream(byte[] expectedChecksum) throws ChecksumMismatchException {\n    if (!Arrays.equals(expectedChecksum, checksum)) {\n      CommonUtils.runQuietly(stream::close);\n      throw new ChecksumMismatchException(expectedChecksum, checksum);\n    }\n\n    return stream;\n  }\n\n  public byte[] checksum() {\n    return checksum;\n  }\n}\n","sourceCodeStart":25,"sourceCodeEnd":53,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-cloud-storage-project/hadoop-tos/src/main/java/org/apache/hadoop/fs/tosfs/object/ObjectContent.java#L25-L53","documentation":"ObjectContent bundles an object InputStream with the checksum the connector computed while reading (ChainTOSInputStream derives it from TOS response headers such as x-tos-hash-crc64ecma). verifiedStream(expected) compares expected against that computed checksum and, on mismatch, quietly closes the stream and throws ChecksumMismatchException (\"Expected checksum is X while actual checksum is Y\"), which extends IOException. It signals that the bytes read do not match the checksum recorded when the object metadata was captured.","triggerScenarios":"Verifying a read against an expected checksum captured earlier while (a) the object was overwritten or truncated by another writer, (b) expected was computed under a different fs.tos.checksum-type (CRC64ECMA default vs CRC32C), or (c) a proxy/HTTP layer corrupted the range payload.","commonSituations":"fs.tos.checksum-type changed between the writing and reading jobs; concurrent writers mutating the same key; unstable middleboxes altering bodies; mixed connector versions.","solutions":["Re-open and re-read the object once to rule out transient corruption","Pin fs.tos.checksum-type to one value (CRC64ECMA or CRC32C) on every client/job that writes and reads the data","If the object was legitimately rewritten, refresh the expected checksum from a fresh objectStatus instead of a stale one","If the mismatch persists on stable data, treat it as corruption: quarantine the object and restore from a replica/backup"],"exampleFix":"// before\ntry (InputStream in = content.verifiedStream(expected)) {\n  consume(in);\n}\n\n// after: re-fetch expected from live metadata, retry once\ntry (InputStream in = content.verifiedStream(expected)) {\n  consume(in);\n} catch (ChecksumMismatchException e) {\n  byte[] fresh = storage.objectStatus(key).checksum();\n  try (ObjectContent c = storage.get(key, 0, -1);\n       InputStream in = c.verifiedStream(fresh)) {\n    consume(in);\n  }\n}","handlingStrategy":"retry","validationCode":"byte[] expected = storage.objectStatus(key).checksum();\ntry (InputStream in = content.verifiedStream(expected)) {\n  consume(in);\n}","typeGuard":null,"tryCatchPattern":"try (InputStream in = content.verifiedStream(expected)) {\n  consume(in);\n} catch (ChecksumMismatchException e) {\n  // one bounded retry with fresh metadata, then surface as corruption\n  byte[] fresh = storage.objectStatus(key).checksum();\n  try (ObjectContent c = storage.get(key, 0, -1);\n       InputStream in = c.verifiedStream(fresh)) {\n    consume(in);\n  }\n}","preventionTips":["Pin fs.tos.checksum-type to one value across all clients","Avoid concurrent writers to a single key","Never ignore a checksum mismatch on a retry; escalate to restore"],"tags":["hadoop-tos","object-storage","data-integrity","checksum","read-path"],"backgroundTag":"checksum-mismatch","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}