Browse Source

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.
Peter Rust 12 years ago
committed by Timothy J Fontaine
parent
commit
82ff891e22
  1. 9
      lib/_http_outgoing.js

9
lib/_http_outgoing.js

@ -21,6 +21,7 @@
var assert = require('assert').ok; var assert = require('assert').ok;
var Stream = require('stream'); var Stream = require('stream');
var timers = require('timers');
var util = require('util'); var util = require('util');
var common = require('_http_common'); var common = require('_http_common');
@ -44,12 +45,14 @@ function utcDate() {
if (!dateCache) { if (!dateCache) {
var d = new Date(); var d = new Date();
dateCache = d.toUTCString(); dateCache = d.toUTCString();
setTimeout(function() { timers.enroll(utcDate, 1000 - d.getMilliseconds());
dateCache = undefined; timers._unrefActive(utcDate);
}, 1000 - d.getMilliseconds());
} }
return dateCache; return dateCache;
} }
utcDate._onTimeout = function() {
dateCache = undefined;
};
function OutgoingMessage() { function OutgoingMessage() {

Loading…
Cancel
Save