Skip to content

Commit 648d668

Browse files
committed
http: emit timeout duration overflow warning sync
Emit the `TimeoutOverflowWarning` synchronously, even when still connecting, to get a better stack trace. With thanks to Anatoli Papirovski for providing helpful tips when writing the test. PR-URL: #18906 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent d83f830 commit 648d668

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

lib/_http_client.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const { urlToOptions, searchParamsSymbol } = require('internal/url');
4040
const { outHeadersKey, ondrain } = require('internal/http');
4141
const { nextTick } = require('internal/process/next_tick');
4242
const errors = require('internal/errors');
43+
const { validateTimerDuration } = require('internal/timers');
4344

4445
const INVALID_PATH_REGEX = /[^\u0021-\u00ff]/;
4546

@@ -678,6 +679,7 @@ function _deferToConnect(method, arguments_, cb) {
678679
}
679680

680681
ClientRequest.prototype.setTimeout = function setTimeout(msecs, callback) {
682+
msecs = validateTimerDuration(msecs);
681683
if (callback) this.once('timeout', callback);
682684

683685
const emitTimeout = () => this.emit('timeout');
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
const common = require('../common');
3+
const http = require('http');
4+
const assert = require('assert');
5+
6+
// Checks that the setTimeout duration overflow warning is emitted
7+
// synchronously and therefore contains a meaningful stacktrace.
8+
9+
process.on('warning', common.mustCall((warning) => {
10+
assert(warning.stack.includes(__filename));
11+
}));
12+
13+
const server = http.createServer((req, resp) => resp.end());
14+
server.listen(common.mustCall(() => {
15+
http.request(`http://localhost:${server.address().port}`)
16+
.setTimeout(2 ** 40)
17+
.on('response', common.mustCall(() => {
18+
server.close();
19+
}))
20+
.end();
21+
}));

0 commit comments

Comments
 (0)