juttle / winston-logrotate

Log rotating transport for Winston
Apache License 2.0
10 stars 8 forks source link

ulimit open file handles reached #14

Open FASTLIKETREE opened 6 years ago

FASTLIKETREE commented 6 years ago

An issue I hit when writing units tests to check log rotate functionality.

When running logs in a loop Rotate.prototype.log does not check if an existing write stream is already being created for a particular file. Instead it checks for a ready flag asynchronously set by logrotate-stream. This results in calling _init() every time you call Rotate.prototype.log, never giving time for the stream to become ready.

This hits my machine open file handle limit (ulimit -n).

Below is a mocha test that exhibits the issue.

it('max file handles', function(done) {
  this.timeout(10000)
  var temp_dir = temp.mkdirSync('winston-logrotate-test');
  var file = path.join(temp_dir, 'rotate.log');
  var logger = new Rotate({
      file: file,
      size: '1k',
      keep: 1
  });

  for (let i = 0; i < 100000; ++ i) {
    logger.log('max log test');
  }
  done();
});