-
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
http2: end
is emitted before error
when destroying client stream
#39400
Comments
I think this might be expected behavior: consider your code like import http2 from 'http2';
import stream from 'stream';
const session = http2.connect('https://petstore.swagger.io/v2/pet/findByStatus?status=available');
const request = session.request({
':path': '/findByStatus?status=available',
'x-trace-id': 'foo',
'user-agent': 'foo-bar/baz, bash'
});
request.on('data', () => {
request.destroy(new Error('error'));
});
request.on('end', () => {
console.log('end');
});
request.end();
stream.promises.pipeline(
request,
new stream.PassThrough()
).then(x => {
console.log('success');
session.close();
}); the pipeline method just connects an empty stream when request is already ended... |
It's not possible as it's not possible to be connected in the same tick you initiate a connection. |
It seems the import http2 from 'http2';
const session = http2.connect('https://0273ea441bca0690c5454e2f3380fe0e/');
const request = session.request();
request.on('data', () => {
request.destroy(new Error('error'));
});
request.on('end', () => {
console.log('end');
});
request.end(); |
I think the issue here is that
|
cc: @nodejs/streams |
This is a very interesting edge case. Consider the following: import stream from 'stream';
const duplex = new stream.Duplex({
read() {},
write(chunk, encoding, callback) {
callback();
}
});
let tick = false
duplex.on('data', function () {
tick = true
process.nextTick(() => {
tick = false
})
this.destroy(new Error('error'));
});
duplex.on('end', function () {
console.log('end', tick);
});
duplex.on('error', console.error);
duplex.push('foo');
duplex.push(null); The problem is that
This looks like a bug we should fix. @ronag wdyt? |
It's a duplex that emitted only Edit: I guess pipeline does not care about the writable side which makes sense as there is no more data to read/pipe to the next stream. |
@mcollina In the issue the writable side has ended but the readable not. |
@szmarczak from @lpinca words ^. |
Looks like node/lib/internal/streams/readable.js Line 1336 in 89adc16
state.errored instead of state.errorEmitted
|
@mcollina I believe in that case |
http2 failed tests.txt with |
Is the change |
I would go with a patch as it's a bad bug. I'd just wait to backport to LTS lines for a bit (or at all). |
I think so. |
Version
v16.4.2
Platform
Linux solus 5.13.1-187.current #1 SMP PREEMPT Wed Jul 7 19:52:26 UTC 2021 x86_64 GNU/Linux
Subsystem
http2
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
Possibly related with #29929 or #35209
The text was updated successfully, but these errors were encountered: