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: reset flowing state if no 'readable' or 'data' listeners. #31036

Closed
wants to merge 5 commits into from

Conversation

ronag
Copy link
Member

@ronag ronag commented Dec 20, 2019

If we don't have any 'readable' or 'data' listeners and we are not about to resume. Then reset flowing state to initial null state.

Fixes: #24474

I don't feel very confident modifying things here but this seems to solve the issue and doesn't break any existing tests.

I would very much like a CITGM on this.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added the stream Issues and PRs related to the stream subsystem. label Dec 20, 2019
If we don't have any 'readable' or 'data' listeners and we are
not about to resume. Then reset flowing state to initial null state.

Fixes: nodejs#24474
@nodejs-github-bot
Copy link
Collaborator

@BridgeAR
Copy link
Member

@lpinca
Copy link
Member

lpinca commented Dec 21, 2019

I'm not sure if resetting to null has side effects but if it does not break anything this LGTM.

@lpinca
Copy link
Member

lpinca commented Dec 21, 2019

@nodejs/streams

@lpinca
Copy link
Member

lpinca commented Dec 21, 2019

A possible side effect is

'use strict';

const assert = require('assert');
const { Readable } = require('stream');

const readable = new Readable({
  read() {}
});

function read() {}

readable.setEncoding('utf8');
readable.on('readable', read);
readable.removeListener('readable', read);
readable.pause();

process.nextTick(function() {
  assert(readable.isPaused()); // Throws.
});

@ronag
Copy link
Member Author

ronag commented Dec 21, 2019

A possible side effect is

Good point! I've tried fixing this as well. However, now I've slightly modified the initial state of paused which might break things outside of test. I could put it behind a private symbol and create a getter to emulate the previous behavior?

Could someone add the WIP label on this so this doesn't accidentally land until the above comment has either been ok:d or resolved?

lib/_stream_readable.js Outdated Show resolved Hide resolved
@lpinca lpinca added the wip Issues and PRs that are still a work in progress. label Dec 21, 2019
@ronag
Copy link
Member Author

ronag commented Dec 21, 2019

Tried to sort the compat issue.

@ronag ronag requested a review from lpinca December 21, 2019 07:51
@lpinca lpinca removed the wip Issues and PRs that are still a work in progress. label Dec 21, 2019
@lpinca
Copy link
Member

lpinca commented Dec 21, 2019

There is one legitimate test failure because readable.isPaused() no longer uses state.flowing.

assert.strictEqual(socket.isPaused(), true);

I think as is this is semver-major.

@ronag
Copy link
Member Author

ronag commented Dec 21, 2019

Tried fixing that as well.

@nodejs-github-bot
Copy link
Collaborator

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm as semver-major

@ronag
Copy link
Member Author

ronag commented Dec 21, 2019

@Trott: Can we get a CITGM?

@lpinca
Copy link
Member

lpinca commented Dec 21, 2019

I think it doesn't necessarily have to be semver-major now. Could be patch.

@lpinca
Copy link
Member

lpinca commented Dec 21, 2019

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@BridgeAR BridgeAR added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Dec 25, 2019
@nodejs-github-bot
Copy link
Collaborator

nodejs-github-bot commented Dec 25, 2019

CI: https://ci.nodejs.org/job/node-test-pull-request/27935/ ✅ (one known flake on arm)

@BridgeAR
Copy link
Member

@mcollina are you fine with this being a patch as suggested by @lpinca?

@mcollina
Copy link
Member

yes, however I would tag this as “baking for lts.

@BridgeAR BridgeAR added the baking-for-lts PRs that need to wait before landing in a LTS release. label Dec 25, 2019
BridgeAR pushed a commit that referenced this pull request Dec 25, 2019
If we don't have any 'readable' or 'data' listeners and we are
not about to resume. Then reset flowing state to initial null state.

PR-URL: #31036
Fixes: #24474
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
@BridgeAR
Copy link
Member

Landed in 3d47c85 🎉

@BridgeAR BridgeAR closed this Dec 25, 2019
BridgeAR pushed a commit that referenced this pull request Jan 3, 2020
If we don't have any 'readable' or 'data' listeners and we are
not about to resume. Then reset flowing state to initial null state.

PR-URL: #31036
Fixes: #24474
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
@BridgeAR BridgeAR mentioned this pull request Jan 7, 2020
targos pushed a commit that referenced this pull request Jan 14, 2020
If we don't have any 'readable' or 'data' listeners and we are
not about to resume. Then reset flowing state to initial null state.

PR-URL: #31036
Fixes: #24474
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
targos pushed a commit that referenced this pull request Jan 14, 2020
If we don't have any 'readable' or 'data' listeners and we are
not about to resume. Then reset flowing state to initial null state.

PR-URL: #31036
Fixes: #24474
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
BethGriggs pushed a commit that referenced this pull request Feb 6, 2020
If we don't have any 'readable' or 'data' listeners and we are
not about to resume. Then reset flowing state to initial null state.

PR-URL: #31036
Fixes: #24474
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
@MylesBorins MylesBorins mentioned this pull request Feb 8, 2020
@targos targos removed the baking-for-lts PRs that need to wait before landing in a LTS release. label Sep 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. stream Issues and PRs related to the stream subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

stream: adding new 'data' handler doesn't resume stream after removing 'readable' handler
7 participants