Skip to content

Piping readable stream to multiple writeable streams results in crash #5820

Closed
@kr3l

Description

@kr3l

If I execute the following code snippet in node >= 4.2.0, it results in the read stream reading the data very fast but not being able to write them out to wr2 equally fast. The memory usage of the process increases very fast until the process exits with an error.

var fs = require('fs');

//M: and L: are local disks with fast read and write
// the .mov file is several gigabytes in size
var rd = fs.createReadStream('M:/A007C003_141024_R7C6.mov');
var wr = fs.createWriteStream('L:/A007C003_141024_R7C6.mov');

//N: is a NAS drive, slow
var wr2 = fs.createWriteStream('N:/A007C003_141024_R7C6.mov');

//read from fast disk, write to both fast and slow disk
rd.pipe(wr);
rd.pipe(wr2);

The script ends with this error:

.\node-4.2.0 test.js
buffer.js:98
    const ui8 = new Uint8Array(size);
                ^

RangeError: Invalid array buffer length
    at new ArrayBuffer (native)
    at new Uint8Array (native)
    at allocate (buffer.js:98:17)
    at new Buffer (buffer.js:49:12)
    at Function.Buffer.concat (buffer.js:234:16)
    at fromList (_stream_readable.js:840:20)
    at ReadStream.Readable.read (_stream_readable.js:339:11)
    at flow (_stream_readable.js:743:26)
    at WriteStream.<anonymous> (_stream_readable.js:601:7)
    at emitNone (events.js:67:13)
    at WriteStream.emit (events.js:166:7)

Earlier versions of node (4.1.2 and below) do not show the same behaviour.

  • Version: v4.2.0
  • Platform: Win10 64bit
  • Subsystem:

Metadata

Metadata

Assignees

No one assigned

    Labels

    fsIssues and PRs related to the fs subsystem / file system.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