{"record":{"id":"f30f21bb3f2c8170","repo":"apache/cassandra","slug":"checksum-didn-t-match-expected-d-actual-d","errorCode":null,"errorMessage":"Checksum didn't match (expected: %d, actual: %d)","messagePattern":"Checksum didn't match \\(expected: (.+?), actual: (.+?)\\)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"critical","filePath":"src/java/org/apache/cassandra/db/streaming/CompressedInputStream.java","lineNumber":206,"sourceCode":"            copyArray = new byte[max((int)(copyArray.length * GROWTH_FACTOR), dst.remaining())];\n\n        input.readFully(copyArray, 0, dst.remaining());\n        dst.put(copyArray, 0, dst.remaining());\n    }\n    private byte[] copyArray;\n\n    private void maybeValidateChecksum(ByteBuffer buffer, int expectedChecksum) throws IOException\n    {\n        double validateChance = validateChecksumChance.getAsDouble();\n\n        if (validateChance >= 1.0d || (validateChance > 0.0d && validateChance > ThreadLocalRandom.current().nextDouble()))\n        {\n            int position = buffer.position();\n            int actualChecksum = (int) checksumType.of(buffer);\n            buffer.position(position); // checksum calculation consumes the buffer, so we must reset its position afterwards\n\n            if (expectedChecksum != actualChecksum)\n                throw new IOException(format(\"Checksum didn't match (expected: %d, actual: %d)\", expectedChecksum, actualChecksum));\n        }\n    }\n\n    @Override\n    public void close()\n    {\n        if (null != buffer)\n        {\n            MemoryUtil.clean(buffer);\n            buffer = null;\n        }\n\n        if (null != compressedChunk)\n        {\n            MemoryUtil.clean(compressedChunk);\n            compressedChunk = null;\n        }\n    }","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/streaming/CompressedInputStream.java#L188-L224","documentation":"During compressed streaming, each chunk carries an Adler/CRC checksum computed by the sender. maybeValidateChecksum recomputes it over the decompressed buffer and compares; on mismatch it throws IOException because the decompressed data is corrupt or was mangled in transit. This protects streaming integrity across the network.","triggerScenarios":"Receiving a compressed chunk whose recomputed checksum differs from the expected checksum sent alongside it — network bit corruption, a buggy/misconfigured compression compressor mismatch, or a partial chunk write followed by reuse of a buffer.","commonSituations":"Faulty NIC/cable/disk causing silent bit flips during streaming; intercepting proxies or encryption layers corrupting payloads; custom compression parameters changed on one node; hardware faults (bad RAM) on the sender.","solutions":["Retry the streaming session — checksum failures are usually transient corruption","Run nodetool scrub / verify on the sending node's SSTables to detect on-disk corruption","Check network hardware and disable/inspect any middleboxes altering payloads","Verify compression parameters and Cassandra versions match on both endpoints","Check dmesg/hardware logs for disk or memory errors"],"exampleFix":"// before\n// no retry on IOException from stream read\nstream.position(pos);\n// after\ntry {\n    stream.position(pos);\n} catch (IOException e) {\n    if (e.getMessage().startsWith(\"Checksum didn't match\"))\n        retryStreamSession(); // re-initiate the failed range\n    else\n        throw e;\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { readStream(); } catch (IOException e) { if (e.getMessage().contains(\"Checksum didn't match\")) retrySession(); else throw e; }","preventionTips":["Monitor node hardware (RAM/disk/NIC) for faults","Run nodetool verify periodically on streamed SSTables","Avoid middleboxes that rewrite payloads","Keep compression settings identical cluster-wide"],"tags":["streaming","checksum","corruption","io"],"backgroundTag":"checksum-mismatch","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}