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

test,doc: address http2 connection abort/network error handling #21861

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/api/http2.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,17 @@ server.on('stream', (stream, headers) => {
'content-type': 'text/html',
':status': 200
});
stream.on('error', (error) => console.log(error));
Copy link
Contributor

Choose a reason for hiding this comment

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

console.log -> console.error?

Copy link
Contributor

Choose a reason for hiding this comment

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

Or maybe just:

stream.on('error', console.error);

Copy link
Member Author

Choose a reason for hiding this comment

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

👍 Switched to the first suggestion – I’d prefer to give a user-defined function here, since that is a bit closer to what one would actually do in real-world code

stream.end('<h1>Hello World</h1>');
});

server.listen(80);
```

Even though HTTP/2 streams and network sockets are not in a 1:1 correspondence,
a network error will destroy each individual streams and must be handled on the
Copy link
Member

Choose a reason for hiding this comment

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

Nit: streams -> stream?

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks, done!

stream level, as shown above.

#### Event: 'timeout'
<!-- YAML
added: v8.4.0
Expand Down
11 changes: 3 additions & 8 deletions test/parallel/test-http2-respond-with-file-connection-abort.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const http2 = require('http2');
const net = require('net');

Expand All @@ -12,6 +13,7 @@ const {

const server = http2.createServer();
server.on('stream', common.mustCall((stream) => {
stream.on('error', (err) => assert.strictEqual(err.code, 'ECONNRESET'));
stream.respondWithFile(process.execPath, {
[HTTP2_HEADER_CONTENT_TYPE]: 'application/octet-stream'
});
Expand All @@ -22,16 +24,9 @@ server.listen(0, common.mustCall(() => {
const req = client.request();

req.on('response', common.mustCall(() => {}));
req.on('data', common.mustCall(() => {
req.on('data', common.mustCallAtLeast(() => {
net.Socket.prototype.destroy.call(client.socket);
server.close();
}));
req.end();
}));

// TODO(addaleax): This is a *hack*. HTTP/2 needs to have a proper way of
// dealing with this kind of issue.
process.once('uncaughtException', (err) => {
if (err.code === 'ECONNRESET') return;
throw err;
});