Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
http: emit timeout duration overflow warning sync
Emit the `TimeoutOverflowWarning` synchronously, even when
still connecting, to get a better stack trace.
  • Loading branch information
addaleax committed Mar 2, 2018
commit 8543d2b0added9f47922015ce9f7359656b33447
2 changes: 2 additions & 0 deletions lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]/;

Expand Down Expand Up @@ -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');
Expand Down
20 changes: 20 additions & 0 deletions test/parallel/test-http-timeout-client-warning.js
Original file line number Diff line number Diff line change
@@ -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();
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know if this would be considered an issue with the test... there's a race condition between the server being closed and the request being processed. Most of these http tests would put the server.close(); in an event listener for end rather than a callback. Not sure if this is expected behaviour or a bug though... I can see a case for both.

Copy link
Contributor

Choose a reason for hiding this comment

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

});
}));