Skip to content

Behavior of readablestreams changed in v10 #20520

Closed
@tmcw

Description

@tmcw
  • Version: v10.0.0
  • Platform:Darwin tmcw.local 17.5.0 Darwin Kernel Version 17.5.0: Fri Apr 13 19:32:32 PDT 2018; root:xnu-4570.51.2~1/RELEASE_X86_64 x86_64
  • Subsystem: stream

Hi Maintainers!

This may be the same underlying issue as #20503 - I'm not confident enough in the node core space enough to tell.

This problem was first noticed in cp-file, a dependency of cpy, which is a dependency of one of my projects. A very distilled test case is:

const fs = require('fs');
const read = fs.createReadStream(__filename);

read.on('readable', () => {
    read.on('data', chunk => {
        console.log('data');
    });
});

This is a program that reads itself, by creating a read stream, waiting for it to be readable, and then assigning a data event listener. It prints data on all node versions < 10, but prints nothing on the Node v10.0.0 release.

In situ, cp-file tries to ensure that a stream is readable before creating the destination directory and then calling .pipe to write the file to disk. As far as I can tell, Node v10 changes the behavior of readable streams such that data events are not emitted if you bind the data event listener after readable is emitted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    streamIssues and PRs related to the stream subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions