-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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: restore flow if there are 'data' handlers after once('readable') #22209
Conversation
This is an alternative implementation of #21696. |
It seems like this one has the same flaws my PR had at the beginning
But the first one is documented now. |
That works exactly as expected. If
Which is as expected. |
Yeah, this may be better as it simplifies the implementation a bit and signifies the fact that you shouldn't use 'readable' with 'data'. But as I said we have to better document it as issues of incorrect usage of streams are constantly popping up. |
8fc5f64
to
a7e57aa
Compare
I'll add some more docs for review tomorrow. |
a7e57aa
to
58b5968
Compare
doc/api/stream.md
Outdated
@@ -618,6 +618,12 @@ instance, when the `readable.resume()` method is called without a listener | |||
attached to the `'data'` event, or when a `'data'` event handler is removed | |||
from the stream. | |||
|
|||
Adding a [`'readable'`][] event handler automatically make the stream to | |||
stop flowing, and the data to be consumed via | |||
[`readable.read()`][]. If the [`'readable'`] event handler is removed, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[`readable.read()`][]
-> [`readable.read()`][stream-read]
?
doc/api/stream.md
Outdated
Adding a [`'readable'`][] event handler automatically make the stream to | ||
stop flowing, and the data to be consumed via | ||
[`readable.read()`][]. If the [`'readable'`] event handler is removed, | ||
then the stream will start flowing again if there is a [`data`][] event |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[`data`][]
-> [`'data'`][]
?
CITGM seems ok. |
58b5968
to
2956304
Compare
@vsemozhetbyt PTAL |
Doc part LGTM. |
@mafintosh @addaleax PTAL. |
@mcollina I think this relates to #21122. What if we don't call const fs = require('fs')
const { resolve } = require('path')
const source = resolve(__dirname, 'index.js')
const target = resolve(__dirname, 'copy.js')
const reader = fs.createReadStream(source)
const writer = fs.createWriteStream(target);
reader.on('close', () => {
console.log('reader closed');
});
writer.on('close', () => {
console.log('writer closed');
});
reader.on('data', () => {
console.log('receive data')
})
reader.on('readable', () => {
// DO NOT `reader.read()`
}) Will print:
However, change the order of binding these two events will result in different behaviors: const fs = require('fs')
const { resolve } = require('path')
const source = resolve(__dirname, 'index.js')
const target = resolve(__dirname, 'copy.js')
const reader = fs.createReadStream(source)
const writer = fs.createWriteStream(target);
reader.on('close', () => {
console.log('reader closed');
});
writer.on('close', () => {
console.log('writer closed');
});
reader.on('readable', () => {
// DO NOT `reader.read()`
})
reader.on('data', () => {
console.log('receive data')
}) Will print nothing and exit. Also, replace |
I see, thanks. |
2956304
to
861124a
Compare
LGTM, nice fix |
@nodejs/build I can't get This looks like an infra issue, see nodejs/build#1468. |
Resume Build: https://ci.nodejs.org/job/node-test-pull-request/16665/ |
Fixes: nodejs#21398 See: nodejs#21696 PR-URL: nodejs#22209 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Mathias Buus <[email protected]>
Resume Build resulted in a green CI run. Landed in 98cf84f. |
Fixes: #21398 See: #21696 PR-URL: #22209 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Mathias Buus <[email protected]>
Fixes: #21398 See: #21696 PR-URL: #22209 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Mathias Buus <[email protected]>
Fixes test failure causes by combination of nodejs/node#22209 and an ambiguous test.
Fixes test failure causes by combination of nodejs/node#22209 and an ambiguous test.
Fixes test failure causes by combination of nodejs/node#22209 and an ambiguous test.
Fixes test failure causes by combination of nodejs/node#22209 and an ambiguous test.
Fixes test failure causes by combination of nodejs/node#22209 and an ambiguous test.
In #18994, we made
'readable'
take precedence over'data'
/resume()
andpause()
. However, we didn't take into account situation where both'readable'
and'data'
event handler were present at the same time. This PR addresses it by starting flowing after'readable'
is removed.Fixes: #21398
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes