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:
parent
8558935084
commit
a280863be6
1 changed files with 9 additions and 1 deletions
|
@ -1082,9 +1082,13 @@ util.inherits(RotatingFileStream, EventEmitter);
|
||||||
RotatingFileStream.prototype._setupNextRot = function () {
|
RotatingFileStream.prototype._setupNextRot = function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
this.rotAt = this._nextRotTime();
|
this.rotAt = this._nextRotTime();
|
||||||
|
var delay = this.rotAt - Date.now();
|
||||||
|
if (delay > 2147483647) {
|
||||||
|
delay = 2147483647;
|
||||||
|
}
|
||||||
this.timeout = setTimeout(
|
this.timeout = setTimeout(
|
||||||
function () { self.rotate(); },
|
function () { self.rotate(); },
|
||||||
this.rotAt - Date.now());
|
delay);
|
||||||
if (typeof (this.timeout.unref) === 'function') {
|
if (typeof (this.timeout.unref) === 'function') {
|
||||||
this.timeout.unref();
|
this.timeout.unref();
|
||||||
}
|
}
|
||||||
|
@ -1175,6 +1179,10 @@ RotatingFileStream.prototype.rotate = function rotate() {
|
||||||
var self = this;
|
var self = this;
|
||||||
var _DEBUG = false;
|
var _DEBUG = false;
|
||||||
|
|
||||||
|
if (self.rotAt && self.rotAt > Date.now()) {
|
||||||
|
return self._setupNextRot();
|
||||||
|
}
|
||||||
|
|
||||||
if (_DEBUG) {
|
if (_DEBUG) {
|
||||||
console.log('-- [%s, pid=%s] rotating %s',
|
console.log('-- [%s, pid=%s] rotating %s',
|
||||||
new Date(), process.pid, self.path);
|
new Date(), process.pid, self.path);
|
||||||
|
|
Loading…
Reference in a new issue