Skip to content

Commit 82ff891

Browse files
prusttjfontaine
authored andcommitted
http: use an unref'd timer to fix delay in exit
There was previously up to a second exit delay when exiting node right after an http request/response, due to the utcDate() function doing a setTimeout to update the cached date/time. Fixing this should increase the performance of our http tests.
1 parent fe17692 commit 82ff891

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

lib/_http_outgoing.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
var assert = require('assert').ok;
2323
var Stream = require('stream');
24+
var timers = require('timers');
2425
var util = require('util');
2526

2627
var common = require('_http_common');
@@ -44,12 +45,14 @@ function utcDate() {
4445
if (!dateCache) {
4546
var d = new Date();
4647
dateCache = d.toUTCString();
47-
setTimeout(function() {
48-
dateCache = undefined;
49-
}, 1000 - d.getMilliseconds());
48+
timers.enroll(utcDate, 1000 - d.getMilliseconds());
49+
timers._unrefActive(utcDate);
5050
}
5151
return dateCache;
5252
}
53+
utcDate._onTimeout = function() {
54+
dateCache = undefined;
55+
};
5356

5457

5558
function OutgoingMessage() {

0 commit comments

Comments
 (0)