-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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.Transform changing order of items #46765
Comments
You accidentally wrote the expected in the current behavior |
I corrected it, thank you |
Do you think you can make an even simpler example? |
What I saw is when you remove the |
That's a good hint. |
sometimes it starts/stops occuring when you change some I wasn't able to replicate the problem without nested Transforms |
When you wrap the: else if (innerTranfrorm.write(row)) {
process.nextTick(callback);
} else like this: } else if (innerTransform.write('outer | ' + row)) {
process.nextTick(() => {
process.nextTick(callback);
});
} else { it solves the problem |
Found another solution and updated my PR |
This is indeed a bug. Here is a simplified version: const stream = require("node:stream");
const s = new stream.Transform({
objectMode: true,
construct(callback) {
this.push('header from constructor\n');
callback();
},
transform: (row, encoding, callback) => {
callback(null, JSON.stringify(row) + '\n');
},
});
s.pipe(process.stdout);
s.write('firstLine');
process.nextTick(() => s.write('secondLine')); This fixes the example: const stream = require("node:stream");
const s = new stream.Transform({
objectMode: true,
construct(callback) {
this.push('header from constructor\n');
process.nextTick(callback);
},
transform: (row, encoding, callback) => {
callback(null, JSON.stringify(row) + '\n');
},
});
s.pipe(process.stdout);
s.write('firstLine');
process.nextTick(() => s.write('secondLine')); So I think we are missing a |
I think https://github.com/nodejs/node/blob/1f75a9513fc829fbd5326a5c9bfa7678b7431eb8/lib/internal/streams/readable.js#LL222C7-L222C7 should be delayed with a |
delaying it with |
Given the following script:
It will error:
This is correct, as you are pushing things after the stream ended. |
I tested with your simplified version |
Signed-off-by: Matteo Collina <[email protected]> Fixes: nodejs#46765
Here is the fix: #46818 |
Signed-off-by: Matteo Collina <[email protected]> Fixes: nodejs#46765
Signed-off-by: Matteo Collina <[email protected]> Fixes: #46765 PR-URL: #46818 Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
Signed-off-by: Matteo Collina <[email protected]> Fixes: #46765 PR-URL: #46818 Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
Signed-off-by: Matteo Collina <[email protected]> Fixes: #46765 PR-URL: #46818 Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
Signed-off-by: Matteo Collina <[email protected]> Fixes: #46765 PR-URL: #46818 Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
Version
v18.14.1
Platform
Linux 703748a51615 5.18.8-051808-generic #202206290850 SMP PREEMPT_DYNAMIC Wed Jun 29 08:59:08 UTC 2022 x86_64 Linux
Subsystem
stream
What steps will reproduce the bug?
How often does it reproduce? Is there a required condition?
always
What is the expected behavior?
What do you see instead?
Additional information
I expect
Transform
to always process incoming items in order, even with reckless code like in the example.The text was updated successfully, but these errors were encountered: