question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

log rotation feature crashes intermittently

See original GitHub issue

The original issue was inexplicably closed and moved over here: https://github.com/winstonjs/winston-daily-rotate-file/issues/9 so I’m reopening it. I’m not using time-based log rotation at all I’m using the core File Transport functionality. I have newer information that may help me find a solution.

I have no idea if it is related to the other crash issues I’ve seen documented, but I am seeing:

Error: ENOENT, open ‘/work/server/server.log’

Every once in a while. In the directory there is a server.log.gz that is 0 bytes along with other log files that have been successfully rotated.

The issue seems to happen when logging frequency and content is high.

I’ve handled the uncaught exception, but there’s not really anything I can do about it since the logger blew chunks.

I’m doing:

winston.add(winston.transports.File, {
    filename: __dirname + '/server.log',
    json: false,
    colorize: true,
    timestamp: true,
    maxsize: 10000000,
    maxFiles: 50,
    showLevel: true,
    tailable: true,
    zippedArchive: true,
});
winston.remove(winston.transports.Console);

The problem seems to be a result of the self._archive variable being set to ‘/work/server/server.log’ when the code enters the compressFile() function. See the code here: https://github.com/winstonjs/winston/blob/master/lib/winston/transports/file.js#L468-L530

Usually, when the code executes: self._stream = fs.createWriteStream(fullname, self.options); fullname is ‘/work/server/server.log’ and self._archive is ‘/work/server/server1.log’

So winston opens a new file for writing new log data (‘/work/server/server.log’) and opens a read stream (‘/work/server/server1.log’) that gets piped through gzip and to a write stream (‘/work/server/server1.log.gz’).

I believe the crash occurs when ‘/work/server/server.log’ sneaks through into the compressFile() function.

I think the sequence is:

  1. self._stream = fs.createWriteStream(fullname, self.options). This does not wait for the ‘open’ event to be emitted before,
  2. compressFile immediately tries to do fs.createReadStream(String(self._archive)) and in some circumstances the file does not exist yet.

That’s my current theory anyway.

My question is: should winston ever gzip ‘/work/server/server.log’? Is this for the non-tailable log rotation case? Am I on the right track?

Okay fine that was three questions.

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:5
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
ghostcommented, Sep 11, 2017

Happening for me as well.

1reaction
SunshowerCcommented, Aug 26, 2019

Any updates on this issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

application crashes at syslog logrotate - LinuxQuestions.org
Under heavy load, the application sometimes crashes during log rotation but very rarely. We are talking maybe once every two months.
Read more >
Error log rotation on crash - Other MySQL® Questions
In our environment, errors log to /var/log/mysql/mysqld.log and we have a logrotate config set to rotate weekly and then gzip. However, if the ......
Read more >
Shoutcast 2 DNAS - log rotation and inconsistencies
Suppose it's 2:30 PM now and the server crashes. When it comes back up, shoutcast will be started and the logs will be...
Read more >
Understanding Crashes and Crash Logs - WWDC18 - Videos
Sudden app crashes are a source of bad user experience and app review rejections. Learn how crash logs can be analyzed, what information......
Read more >
Resolve Acrobat intermittent crashes on Windows
Solution 4: Launch Acrobat Distiller and check if Acrobat is activated · Press Windows key + R to open the Run command window....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found