From 8543d2b0added9f47922015ce9f7359656b33447 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Wed, 21 Feb 2018 17:52:35 +0100 Subject: [PATCH 1/2] http: emit timeout duration overflow warning sync Emit the `TimeoutOverflowWarning` synchronously, even when still connecting, to get a better stack trace. --- lib/_http_client.js | 2 ++ .../test-http-timeout-client-warning.js | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 test/parallel/test-http-timeout-client-warning.js diff --git a/lib/_http_client.js b/lib/_http_client.js index 727dc649c016ae..7bf485b47e60aa 100644 --- a/lib/_http_client.js +++ b/lib/_http_client.js @@ -40,6 +40,7 @@ const { urlToOptions, searchParamsSymbol } = require('internal/url'); const { outHeadersKey, ondrain } = require('internal/http'); const { nextTick } = require('internal/process/next_tick'); const errors = require('internal/errors'); +const { validateTimerDuration } = require('internal/timers'); const INVALID_PATH_REGEX = /[^\u0021-\u00ff]/; @@ -678,6 +679,7 @@ function _deferToConnect(method, arguments_, cb) { } ClientRequest.prototype.setTimeout = function setTimeout(msecs, callback) { + msecs = validateTimerDuration(msecs); if (callback) this.once('timeout', callback); const emitTimeout = () => this.emit('timeout'); diff --git a/test/parallel/test-http-timeout-client-warning.js b/test/parallel/test-http-timeout-client-warning.js new file mode 100644 index 00000000000000..1c91fc00dc1800 --- /dev/null +++ b/test/parallel/test-http-timeout-client-warning.js @@ -0,0 +1,20 @@ +'use strict'; +const common = require('../common'); +const http = require('http'); +const assert = require('assert'); + +// Checks that the setTimeout duration overflow warning is emitted +// synchronously and therefore contains a meaningful stacktrace. + +process.on('warning', common.mustCall((warning) => { + assert(warning.stack.includes(__filename)); +})); + +const server = http.createServer((req, resp) => resp.end()); +server.listen(common.mustCall(() => { + http.request(`http://localhost:${server.address().port}`) + .setTimeout(2 ** 40) + .end(() => { + server.close(); + }); +})); From 30444741c0520c5eb1aa9ee5e76cd75feefd3ca0 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 2 Mar 2018 13:15:26 +0000 Subject: [PATCH 2/2] =?UTF-8?q?[squash]=20fixup=20test=20with=20apapirovsk?= =?UTF-8?q?i=E2=80=99s=20suggestion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/parallel/test-http-timeout-client-warning.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-http-timeout-client-warning.js b/test/parallel/test-http-timeout-client-warning.js index 1c91fc00dc1800..f11515b95fe340 100644 --- a/test/parallel/test-http-timeout-client-warning.js +++ b/test/parallel/test-http-timeout-client-warning.js @@ -14,7 +14,8 @@ const server = http.createServer((req, resp) => resp.end()); server.listen(common.mustCall(() => { http.request(`http://localhost:${server.address().port}`) .setTimeout(2 ** 40) - .end(() => { + .on('response', common.mustCall(() => { server.close(); - }); + })) + .end(); }));