Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stream.pipeline() does not call the callback on completion #34059

Closed
matdodgson opened this issue Jun 26, 2020 · 6 comments
Closed

Stream.pipeline() does not call the callback on completion #34059

matdodgson opened this issue Jun 26, 2020 · 6 comments
Labels
stream Issues and PRs related to the stream subsystem.

Comments

@matdodgson
Copy link

matdodgson commented Jun 26, 2020

  • Version: 12.18.0 and 14.4.0
  • Platform: Ubuntu 20.04 LTS
  • Subsystem:

I use the following code to test the callback of the pipeline() function under node 12.18.0 and node 14.4.0:

'use strict';

import {pipeline, Readable} from 'stream';
import {createWriteStream} from 'fs';

pipeline(
    Readable.from(['a', 'b', 'c', '\r\n']),
    process.stdout,
    (err) => {
        console.log('finish callback stdout');
    }
);

pipeline(
    Readable.from(['a', 'b', 'c', '\r\n']),
    createWriteStream('outfile.txt'),
    (err) => {
        console.log('finish callback file write stream');
    }
);

Under Node 12.18.0, the callback on the second pipeline() is called on completion, but the callback on the first is not.
Same problem on Node 14.4.0.

Related to #26550 and maybe also #33237

@jasnell jasnell added the stream Issues and PRs related to the stream subsystem. label Jun 26, 2020
@jasnell
Copy link
Member

jasnell commented Jun 26, 2020

@nodejs/streams

@ronag
Copy link
Member

ronag commented Jun 26, 2020

process.stdout + end() in pipe @vweevers. Maybe related #32373

@mcollina
Copy link
Member

I thought #32373 was supposed to fix this.

@ronag
Copy link
Member

ronag commented Jun 26, 2020

This works as intended. The callback is called in both cases. At least on Node 14.

The stdout example doesn't print anything because pipeline closes stdout before the callback is invoked, hence the console.log (which uses stdout) doesn't do anything. Changing to console.error will properly print as expected.

@mcollina
Copy link
Member

I think we can close.

@matdodgson
Copy link
Author

matdodgson commented Jun 29, 2020

Apologies - should have used better testing code! The problem is fixed in v14 (I assume #32373) so just waiting on the back port to v12.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stream Issues and PRs related to the stream subsystem.
Projects
None yet
Development

No branches or pull requests

4 participants