From 82ff891e226ecadde68d000a12e7eb1fd0a17d13 Mon Sep 17 00:00:00 2001 From: Peter Rust Date: Sun, 7 Jul 2013 21:11:22 -0700 Subject: [PATCH] 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. --- lib/_http_outgoing.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index 8455b91603..66ed47a9bf 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -21,6 +21,7 @@ var assert = require('assert').ok; var Stream = require('stream'); +var timers = require('timers'); var util = require('util'); var common = require('_http_common'); @@ -44,12 +45,14 @@ function utcDate() { if (!dateCache) { var d = new Date(); dateCache = d.toUTCString(); - setTimeout(function() { - dateCache = undefined; - }, 1000 - d.getMilliseconds()); + timers.enroll(utcDate, 1000 - d.getMilliseconds()); + timers._unrefActive(utcDate); } return dateCache; } +utcDate._onTimeout = function() { + dateCache = undefined; +}; function OutgoingMessage() {