From a280863be62c48cf8ea9597e28c8370f4cd1cd91 Mon Sep 17 00:00:00 2001 From: Daniel Juhl Date: Sat, 1 Nov 2014 11:20:20 +0100 Subject: [PATCH] Handle far future timeouts for logrotation Limit the delay to 2147483647 and then check in rotate() whether we should actually rotate the files or just issue another timeout. Fixes #184, #185. --- lib/bunyan.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/bunyan.js b/lib/bunyan.js index 18632dd..8461118 100644 --- a/lib/bunyan.js +++ b/lib/bunyan.js @@ -1082,9 +1082,13 @@ util.inherits(RotatingFileStream, EventEmitter); RotatingFileStream.prototype._setupNextRot = function () { var self = this; this.rotAt = this._nextRotTime(); + var delay = this.rotAt - Date.now(); + if (delay > 2147483647) { + delay = 2147483647; + } this.timeout = setTimeout( function () { self.rotate(); }, - this.rotAt - Date.now()); + delay); if (typeof (this.timeout.unref) === 'function') { this.timeout.unref(); } @@ -1175,6 +1179,10 @@ RotatingFileStream.prototype.rotate = function rotate() { var self = this; var _DEBUG = false; + if (self.rotAt && self.rotAt > Date.now()) { + return self._setupNextRot(); + } + if (_DEBUG) { console.log('-- [%s, pid=%s] rotating %s', new Date(), process.pid, self.path);