Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
11 changes: 9 additions & 2 deletions lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -739,11 +739,18 @@ assignFunctionName(EE.captureRejectionSymbol, function(err, event, ...args) {
});

function checkConnections() {
if (this.headersTimeout === 0 && this.requestTimeout === 0) {
const headersTimeout =
NumberIsFinite(this.headersTimeout) && this.headersTimeout >= 0 ?
this.headersTimeout : 0;
const requestTimeout =
NumberIsFinite(this.requestTimeout) && this.requestTimeout >= 0 ?
this.requestTimeout : 0;

if (headersTimeout === 0 && requestTimeout === 0) {
return;
}

const expired = this[kConnections].expired(this.headersTimeout, this.requestTimeout);
const expired = this[kConnections].expired(headersTimeout, requestTimeout);

for (let i = 0; i < expired.length; i++) {
const socket = expired[i].socket;
Expand Down
33 changes: 33 additions & 0 deletions test/parallel/test-http-server-invalid-headers-timeout-no-abort.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict';

require('../common');
const assert = require('assert');
const { spawnSync } = require('child_process');

if (process.argv[2] === 'child') {
const { createServer } = require('http');

const server = createServer({
connectionsCheckingInterval: 1,
}, (_req, res) => {
res.end('ok');
});

server.headersTimeout = 'im-not-a-number';

server.listen(0, '127.0.0.1', () => {
setTimeout(() => {
server.close(() => process.exit(0));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not just check whether .close() has been called? And that way we avoid the child part

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Because the buggy behaviour crashes the whole process at native level, so the JS assertion wouldn't run

}, 50);
});
} else {
// Run the repro in a child so the native crash is observable without failing the whole run
const { signal, status, stderr } = spawnSync(
process.execPath,
[__filename, 'child'],
{ encoding: 'utf8' },
);

assert.strictEqual(signal, null);
assert.strictEqual(status, 0, stderr);
Comment on lines +25 to +32

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These kinds of tests make me nervous 😅. Do we already have something similar in the repo for HTTP?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

}
Loading