-
Notifications
You must be signed in to change notification settings - Fork 30k
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
aborting stream using the signal does not close the stream when the from generator never finish #47133
Comments
map
and forEach
operators need to wait for another item before aborting
I see that this happens with async generator/iterator when next but not awaited and then // Keep process open
setInterval(() => {
}, 10000);
let resolve;
const promise = new Promise(res => resolve = res);
async function* neverEnding() {
yield 1;
await promise;
yield 2;
yield 3;
}
async function run() {
const iterator = neverEnding();
console.log(await iterator.next());
const res = iterator.next();
console.log(await iterator.throw(new Error('throw error')));
console.log('nothing here')
}
run()
.then(result => console.log('success', result))
.catch(error => console.log('failure', error)) what get logged is:
is there something we can do to fix this? or this is JavaScript engine (V8) internal bug? |
Looking at the Generator In the |
https://tc39.es/ecma262/#sec-properties-of-asyncgenerator-intances are the possible values, and GeneratorState is a slot on sync generators, not async generators. |
Thanks @ljharb, so the example of the async generator not throwing is the expected behavior? |
I'm not sure what the expected behavior is here tbh. However, by aborting after 10ms, you're basically making a race condition - I think there's no guarantee that |
the 10ms is just an example it can be 1s as well and the same result,
Lets say I have this use case: code: const ac = new AbortController();
setTimeout(() => {
console.log('10s passed')
ac.abort();
}, 10000);
process.stdin
.map(item => {
console.log('item', item)
return item.toString();
}, {signal: ac.signal})
.take(10, {signal: ac.signal})
.toArray({signal: ac.signal})
.then(arr => {
console.log('success', arr);
})
.catch((e) => {
console.error('Aborted', e);
}); In the current behavior, if you don't type anything and 10s pass, the I don't wanna wait for user input when I close the stream, I expect that when I call |
Your |
This is why I don't pass them a signal |
can I work on this issue? |
The problem is if this is even possible, After talking to @giltayar it seems like this can't be fixed as this is how async generator work WDYT @benjamingr |
I was OOO for a while and I'll be abroad until after Passover so my capacity is limited (hence why I didn't weigh in on the transform issue even though I still think the fix is unintuitive). This just looks like a bug to me where the error is not being propagated correctly, when the stream is destroyed catch should be called with an AbortError even if the generator is being thrown into. |
If you remove |
Version
v20.0.0-pre (master)
Platform
Darwin MBP 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 arm64
Subsystem
No response
What steps will reproduce the bug?
This fails as the
catch
is not calledHow often does it reproduce? Is there a required condition?
always
What is the expected behavior? Why is that the expected behavior?
to close the stream
What do you see instead?
error:
Additional information
If I omit the ``addAbortSignal(ac.signal, stream);
, the
stream.destroy` function is not even calledBut when I add the abort signal (
addAbortSignal(ac.signal, stream);
) to the original stream it does get called but still, the test fails.this is because we get to this line:
node/lib/internal/streams/from.js
Line 69 in 3a648af
but not to this:
node/lib/internal/streams/from.js
Line 70 in 3a648af
The text was updated successfully, but these errors were encountered: