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

Legacy stream throws unhandled stream error when it is handled #35237

Closed
szmarczak opened this issue Sep 17, 2020 · 3 comments
Closed

Legacy stream throws unhandled stream error when it is handled #35237

szmarczak opened this issue Sep 17, 2020 · 3 comments

Comments

@szmarczak
Copy link
Member

  • Version: 14.11.0
  • Platform: Linux solus 5.6.19-158.current #1 SMP PREEMPT Sun Jul 26 14:17:01 UTC 2020 x86_64 GNU/Linux
  • Subsystem: stream

What steps will reproduce the bug?

const {Stream: LegacyStream, PassThrough} = require('stream');

const destination = new PassThrough();
destination.once('error', () => {});

const stream = new LegacyStream();
stream.pipe(destination);

destination.destroy(new Error('this should be handled'));

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

Always.

What is the expected behavior?

No error.

What do you see instead?

internal/streams/legacy.js:61
      throw er; // Unhandled stream error in pipe.
      ^

Error: this should be handled
    at Object.<anonymous> (/home/szm/Desktop/got/demo.js:9:21)
    at Module._compile (internal/modules/cjs/loader.js:1076:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
    at Module.load (internal/modules/cjs/loader.js:941:32)
    at Function.Module._load (internal/modules/cjs/loader.js:782:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47

Additional information

sindresorhus/got#887

@targos
Copy link
Member

targos commented Sep 18, 2020

@nodejs/streams

@ronag
Copy link
Member

ronag commented Sep 18, 2020

If you use on instead of once that will resolve the issue.

The following pattern used in Stream.pipe is a bit unfortunate in the case of once:

    if (EE.listenerCount(this, 'error') === 0) {
      throw er; // Unhandled stream error in pipe.
    }

We do something similar in Readable.pipe though I'm surprised it doesn't have the same issue.

@ronag
Copy link
Member

ronag commented Sep 18, 2020

Interestingly Readable.pipe has no 'error' listener on src.

ronag added a commit to nxtedition/node that referenced this issue Sep 22, 2020
@Trott Trott closed this as completed in 6be80e1 Sep 23, 2020
joesepi pushed a commit to joesepi/node that referenced this issue Jan 8, 2021
Fixes: nodejs#35237

PR-URL: nodejs#35257
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
targos pushed a commit that referenced this issue May 16, 2021
Fixes: #35237

PR-URL: #35257
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
targos pushed a commit that referenced this issue Jun 11, 2021
Fixes: #35237

PR-URL: #35257
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants