Skip to content

createZstdCompress throw error if set constants.ZSTD_c_nbWorkers #59899

@wszgrcy

Description

@wszgrcy

Version

22.17.0

Platform

Microsoft Windows NT 10.0.19045.0 x64

Subsystem

No response

What steps will reproduce the bug?

use zstd compress file

import fs from 'fs';
import path from 'path';
import { Readable } from 'stream';
import { pipeline } from 'stream/promises';
import { constants, createZstdCompress } from 'zlib';
(async () => {
  function createBlankStream(count: number) {
    return new (class extends Readable {
      readCount = 0;
      constructor() {
        super({ highWaterMark: 8 * 1024 * 1024 });
      }
      override _read(size: number) {
        this.readCount += size;
        const needSize = this.readCount > count ? size - (this.readCount - count) : size;
        this.push(Buffer.alloc(needSize, 0));
        if (needSize !== size) {
          this.push(null);
        }
      }
    })();
  }
  let zstdC = createZstdCompress({
    params: {
      [constants.ZSTD_c_compressionLevel]: 1,
      [constants.ZSTD_c_nbWorkers]: 1,
    },
  });
//If no exceptions are reported, you can try increasing the buffer
  await pipeline(createBlankStream(8 * 1024 * 1024+1), zstdC, fs.createWriteStream(path.join(process.cwd(), '11.tar')));
})();

How often does it reproduce? Is there a required condition?

This bug is 100% reproducible.

What is the expected behavior? Why is that the expected behavior?

work

What do you see instead?

Error [ERR_STREAM_PUSH_AFTER_EOF]: stream.push() after EOF
    at readableAddChunkPushByteMode (node:internal/streams/readable:495:28)
    at Readable.push (node:internal/streams/readable:392:5)
    at ZstdCompress.processCallback (node:zlib:536:32)
Emitted 'error' event on ZstdCompress instance at:
    at emitErrorNT (node:internal/streams/destroy:170:8)
    at emitErrorCloseNT (node:internal/streams/destroy:129:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:90:21) {
  code: 'ERR_STREAM_PUSH_AFTER_EOF'
}

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions