Sitelet https://github.com/nodejs/node/issues/54131
Skip to content

stream/promise finished behavior changed when upgrade from 20.13.1 to 20.16.0 #54131

Description

@zhuxb711

Version

20.16.0

Platform

UNIX & Windows

Subsystem

No response

What steps will reproduce the bug?

I use he archiver from package "archiver": "^7.0.1" and try to archive some files to a stream. I use finished function to wait for the stream completed.

import archiver from 'archiver';
import * as memoryStream from 'memory-streams';
import * as streamPromise from 'stream/promises';

function dosomething() {
    const highWaterMark = 8 * 1024 * 1024;
    const zipStream = new memoryStream.WritableStream({
      emitClose: true,
      autoDestroy: true,
      highWaterMark: highWaterMark
    });
    
    const zipArchiver = archiver.create('zip', {
      zlib: {
        level: 9
      },
      highWaterMark: highWaterMark
    });
    
    zipArchiver.pipe(zipStream);
    zipArchiver.on('error', (err) => {
      // Print error
    });
    zipArchiver.on('warning', (err) => {
      // Print warning
    });
    
    // Append some entries to the archive
    zipArchiver.append(/*<ReadableStream or buffer>*/, {
      name: 'test',
      date: new Date()
    });
    
    await zipArchiver.finalize();
    
    // Node.js v20.13.1 this function will return
    // Node.js v20.16.0 this function will never return
    await streamPromise.finished(zipStream);
}

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

Always

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

finished should behave as the Nodejs v20.13.1

What do you see instead?

finished never returns

Additional information

No response

Activity

  1. jakecastelli commented on Jul 31, 2024

    @jakecastelli
    Member

    Thanks for the report, the issue actually comes from memory-streams package using a very old implementation of the stream "readable-stream": "~1.0.2" and it does not know what pendingcb is on the WritableStream, therefore the Promise never resolved.

    I could submit a patch at the meanwhile to fix this but please be mindful the package has been publicly archived.

  2. zhuxb711 commented on Jul 31, 2024

    @zhuxb711
    Author

    Could suggest any alternative package for something like "in memory stream"?

  3. jakecastelli commented on Oct 4, 2024

    @jakecastelli
    Member

    This is fixed in the v20.18

  4. zhuxb711 commented on Oct 8, 2024

    @zhuxb711
    Author

    Thanks~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    streamIssues and PRs related to Node.js streams.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions