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.
This commit is contained in:
Daniel Juhl 2014-11-01 11:20:20 +01:00 committed by Trent Mick
parent 8558935084
commit a280863be6

View file

@ -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);