zlib: native zstd decompression sporadically reports ZSTD_error_checksum_wrong on valid frames and aborts with a `!closed_` assertion
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 12/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- javascript
- Lĩnh vực
- backend
Hướng nghiên cứu
The failure is in the native zstd decompression path: src/node_zlib.cc around the CompressionStream Write method (line 553, the !closed_ assertion) and the ZstdDecompressContext. Start by running the attached repro script on a build to confirm both symptoms. Done would mean a fix that removes the spurious checksum errors and the abort under concurrent compression, with a regression test in test/parallel for zstd streams.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Version
Version - v24.21.0 (also reproduced on v24.22.3 and v26.13.1) - Windows 11 x64 (official node.exe binaries)
Platform
Subsystem
No response
What steps will reproduce the bug?
Expected behavior
Decompressing structurally valid, intact Zstandard frames always succeeds, and concurrent compression + decompression in one process never aborts the process.
Actual behavior
Two manifestations, both non-deterministic, with intact frame bytes:
zlib.zstdDecompressSync(frame)on a valid frame sporadically throws
Error: Restored data doesn't match checksum(code: 'ZSTD_error_checksum_wrong').
The same frame decodes successfully on most attempts and after a retry.- With concurrent
zlib.zstdCompress(async, libuv threadpool) and
zlib.zstdDecompressSync/streamwriteSync(main thread) in the same process,
the process aborts:
Assertion failed: !closed_ && "already finalized"
node::CompressionStream<node::ZstdDecompressContext>::Write(
uint32_t, const char *, uint32_t, char *, uint32_t)
[CompressionContext = node::ZstdDecompressContext, async = false] at src\node_zlib.cc:553
How often does it reproduce? Is there a required condition?
What is the expected behavior? Why is that the expected behavior?
Reproduction
Self-contained (no external data); compress 1500 low-compressibility records into
concatenated checksummed frames, then:
const zlib = require('zlib');
const { promisify } = require('util');
const zstdCompressAsync = promisify(zlib.zstdCompress);
const CK = { params: { [zlib.constants.ZSTD_c_checksumFlag]: 1 } };
let seed = 123456789;
const rnd = () => (seed = (seed * 1103515245 + 12345) & 0x7fffffff) / 0x7fffffff;
const A = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
const text = n => { let s = ''; for (let i = 0; i < n; i++) s += A[(rnd() * A.length) | 0]; return s; };
const frames = [];
for (let i = 0; i < 1500; i++)
frames.push(zlib.zstdCompressSync(Buffer.from(JSON.stringify({ i, t: text(1200 + ((rnd() * 1800) | 0)) }) + '\n'), CK));
const blob = Buffer.concat(frames);
const ranges = []; let off = 0;
for (const f of frames) { ranges.push([off, off + f.length]); off += f.length; }
// (1) repeated synchronous one-shot decode
let bad = 0;
for (let pass = 0; pass < 20; pass++)
for (const [s, e] of ranges) { try { zlib.zstdDecompressSync(blob.subarray(s, e)); } catch { bad++; } }
console.log('spurious checksum failures:', bad); // > 0 on affected versions
// (2) concurrent compression (threadpool) + decompression (main thread)
let stop = false;
const payload = Buffer.from('y'.repeat(2000));
(async () => {
(async () => { while (!stop) await Promise.all(Array.from({ length: 8 }, () => zstdCompressAsync(payload, CK))); })();
const stream = zlib.createZstdDecompress({ chunkSize: 1 << 20 });
const handle = stream._handle;
const out = Buffer.allocUnsafe(1 << 20);
const ek = Reflect.ownKeys(stream).find(k => typeof k === 'symbol' && k.description === 'kError');
let derr; stream.on('error', e => { derr ??= e; });
try {
for (let pass = 0; pass < 15; pass++)
for (const [s, e] of ranges) {
const input = blob.subarray(s, e);
let io = 0, ir = input.length;
for (;;) {
handle.writeSync(stream._defaultFlushFlag, input, io, ir, out, 0, out.length);
if (derr) throw derr;
if (stream[ek] !== null) throw stream[ek];
const oa = stream._writeState[0], ia = stream._writeState[1];
if (oa !== 0) break;
io += ir - ia; ir = ia;
}
}
} finally { stop = true; stream.close(); }
})();
What do you see instead?
Observed on the versions above:
- Phase (1): spurious
ZSTD_error_checksum_wrongon ~50% of passes (e.g. 10/20, 12/20, 10/20). - Phase (2): the process aborts within a few passes with the
!closed_assertion above.
Additional information
Notes
- The frame bytes are not corrupt: the same frames decode correctly in isolation,
and a fresh decoder/retry usually succeeds. Failures are non-deterministic and
appear after compression has run in the same process. - The synchronous one-shot API is affected even single-threaded; the native
already finalizedabort specifically requires concurrent threadpool
compression alongside decompression. - This is not Electron-specific — reproduced with the official standalone
node.exe binaries.## Impact
Applications that store data as concatenated checksummed zstd frames and
compress/decompress concurrently (e.g. append-on-write + read-on-load) see
intermittent "corrupt data" errors and occasional native process aborts.
- Ngôn ngữ chính
- JavaScript
- Star
- 124k
- Fork
- 38k
- Merge trung bình
- 4 ngày 2 giờ
- Pull request đã merge (30 ngày)
- 266
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của nodejs/node
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 69/100
Maintainer thường phản hồi trong vòng 1 ngày
-
fs: document readStream.start and readStream.endCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởdoc
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
nodejs/node#67848 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
doc: document the Buffer.prototype.*Slice() methodsCó thể đã có người làm @AyushCipher đã nhận hôm nay. Đang mởdoc
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
nodejs/node#67847 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`styleText` fast path bypasses `options` and `options.validateStream` validationCó thể đã có người làm @GBra-4-669 đã nhận 8 ngày trước. Đang mởutil
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
riscv64
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
nodejs/node#67655 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
bug triage needed
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 2 ngày
-
[Resource]: PersephoneĐang mởresource-submission validation-passed
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
hesreallyhim/awesome-claude-code#3773 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
tabatkins/railroad-diagrams#129 ·
-
web: api() turns a null or object-valued error body into a TypeError or "[object Object]" and loses the statusCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
OCM: shares using the `embedded` protocol are rejected with "Missing sharedSecret in protocol"Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày