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

Readable Pause event not triggered when unpipe causes the pause #32470

Closed
casret opened this issue Mar 24, 2020 · 3 comments
Closed

Readable Pause event not triggered when unpipe causes the pause #32470

casret opened this issue Mar 24, 2020 · 3 comments
Labels
stream Issues and PRs related to the stream subsystem.

Comments

@casret
Copy link

casret commented Mar 24, 2020

  • Version: v12.16.1 v13.9.0
  • Platform: Darwin *** 19.2.0 Darwin Kernel Version 19.2.0: Sat Nov 9 03:47:04 PST 2019; root:xnu-6153.61.1~20/RELEASE_X86_64 x86_64 i386 MacBookPro14,1 Darwin
  • Subsystem: stream

What steps will reproduce the bug?

const fs = require('fs');
const readable = fs.createReadStream("in")
const writable = fs.createWriteStream('out')
readable.on("resume", () => console.log("resume called"))
readable.on("pause", () => console.log("pause called"))
console.log(readable.isPaused())
readable.pipe(writable);
console.log(readable.isPaused())
readable.unpipe(writable);
console.log(readable.isPaused())

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

Every time.

What is the expected behavior?

I would expect the pause event to occur (and "pause called" to be written to the console).

What do you see instead?

Nothing

Additional information

Though the docs say that pause will be emitted when pause() is called, it also says that about the resume event, but the resume event is emitted on first pipe(), so it's inconsistent.

@ronag
Copy link
Member

ronag commented Mar 24, 2020

unpipe() doesn't actually call pause() it just stops the flow. Though I guess for consistency pipe should probably do the reverse or vice versa...

@ronag
Copy link
Member

ronag commented Mar 24, 2020

@nodejs/streams

@ronag ronag added the stream Issues and PRs related to the stream subsystem. label Mar 24, 2020
@casret
Copy link
Author

casret commented Mar 24, 2020

I don't mind if we add a couple other events (pipe/unpipe), but I do need to know when the stream gets paused so I can deal with it on the external resource.

ronag added a commit to nxtedition/node that referenced this issue Mar 24, 2020
unpipe should use pause() instead of mutating
state.flowing directly so that pausing side
effects such as emitting 'pause' are properly
performed.

Fixes: nodejs#32470
@casret casret changed the title Readeable Pause event not triggered when unpipe causes the pause Readable Pause event not triggered when unpipe causes the pause Mar 25, 2020
MylesBorins pushed a commit that referenced this issue Mar 26, 2020
unpipe should use pause() instead of mutating
state.flowing directly so that pausing side
effects such as emitting 'pause' are properly
performed.

Fixes: #32470

PR-URL: #32476
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
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

Successfully merging a pull request may close this issue.

2 participants