From d9c5970be21a7db09607fd88eaf4bffdd9b62fbe Mon Sep 17 00:00:00 2001 From: Martijn Schrage Date: Mon, 1 Feb 2016 12:41:59 +0100 Subject: [PATCH] Don't advance to next rotation time when timeout fires early Fixes #344 --- AUTHORS | 1 + CHANGES.md | 5 +++++ lib/bunyan.js | 8 ++++++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/AUTHORS b/AUTHORS index 8f2b207..29de52b 100644 --- a/AUTHORS +++ b/AUTHORS @@ -34,3 +34,4 @@ Mark Stosberg (https://github.com/markstos) Alexander Ray (https://github.com/aray12) Adam Lynch (https://github.com/adam-lynch) Michael Nisi (https://github.com/michaelnisi) +Martijn Schrage (https://github.com/Oblosys) diff --git a/CHANGES.md b/CHANGES.md index aea53c2..b9436d1 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,11 @@ Known issues: ## 1.7.1 (not yet released) +- [issue #344] Fix "rotating-file" Bunyan streams to not miss rotations when configured + for a period greater than approximately 25 days. Before this there was an issue + where periods greater than node.js's maximum `setTimeout` length would fail to rotate. + (By Martijn Schrage.) + - [issue #234, pull #345] Improve `bunyan` CLI rendering of "res" field HTTP responses to not show two blank lines for an empty body. (By Michael Nisi.) diff --git a/lib/bunyan.js b/lib/bunyan.js index 1e41eef..04d70d5 100644 --- a/lib/bunyan.js +++ b/lib/bunyan.js @@ -1219,8 +1219,12 @@ RotatingFileStream = function RotatingFileStream(options) { util.inherits(RotatingFileStream, EventEmitter); RotatingFileStream.prototype._setupNextRot = function () { - var self = this; this.rotAt = this._nextRotTime(); + this._setRotationTimer(); +} + +RotatingFileStream.prototype._setRotationTimer = function () { + var self = this; var delay = this.rotAt - Date.now(); // Cap timeout to Node's max setTimeout, see // . @@ -1324,7 +1328,7 @@ RotatingFileStream.prototype.rotate = function rotate() { // If rotation period is > ~25 days, we have to break into multiple // setTimeout's. See . if (self.rotAt && self.rotAt > Date.now()) { - return self._setupNextRot(); + return self._setRotationTimer(); } if (_DEBUG) {