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.

Error when logrotate and compressed a log file being tailed

See original GitHub issue

Hi @iccicci ,

I have my stream config as follow: { interval: '10s', compress: (source, dest) => 'cat ${source} | gzip -c9 > ${dest}.gz', maxFiles: 3 }

I was monitoring the log file with tail -F, when it comes to the rotation time, it did not generate the .gz file and the writing stream was stopped

I have received the error message as follow: { [Error: EPERM: operation not permitted, stat 'C:\git\***\log\access.log'] errno: -4048, code: 'EPERM', syscall: 'stat', path: 'C:\\git\\***\\log\\access.log' }

Error [ERR_STREAM_DESTROYED]: Cannot call write after a stream was destroyed at doWrite (_stream_writable.js:411:19) at writeOrBuffer (_stream_writable.js:399:5) at RotatingFileStream.Writable.write (_stream_writable.js:299:11)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
icciccicommented, Dec 2, 2019

Hi @FelixChow ,

first of all, which version of the package are you using?

From the error reported it’s clear we are facing a permissions problem. Looking at the filename it seems to be the not rotated filename while the reported problem is about rotation; this makes me think you have right privileges on that file. What I don’t know is tail behavior under Windows. Could it be the root cause of the problem? Do you have the same experience without the tail command in execution?

As last (but this is not related with your problem), in your compressor function you are adding ".gz" at the destination file and you are using history (maxFiles: 3); the package remembers the destination file it generates, it can’t know you are adding that extension; so history won’t work as expected. If you want to add an extension to the filename it’s better to use a filename generator function doing that and keep untouched the destination file name in the compressor function.

Please let me know, iCC

0reactions
yicommented, Sep 25, 2020

I have just experienced the same issue, and found that is causes by race condition of workers. When deployed with pm2, the application has no master, and all cluster workers are writing to the same file path, which conflicts with each other.

To solve this problem, I added a leader election to workers to make sure only one worker can rotate the log file. I hope this rts module could provide manually start/stop rotation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Logrotate Error: Unable to open ... for compression
It means that /var/log/mylog.1 does not exist or the permissions/ownership do not allow that file to be compressed.
Read more >
Continuously monitor logs with tail that are occasionally rotated
As far as I understand, the problem is that when the log is rotated, there is a new file created, and the running...
Read more >
logrotate(8) - Linux manual page - man7.org
It allows automatic rotation, compression, removal, and mailing of log files. Each log file may be handled daily, weekly, monthly, or when it ......
Read more >
Rotating Logs With Logrotate in Linux - Baeldung
logrotate is a log managing command-line tool in Linux. ... Specifically, any log files that are matched will be compressed upon rotation.
Read more >
Why doesnt "tail" work to truncate log files? - Stack Overflow
... of the log rotate 5 # rotate once the file is bigger than 2k size 2k # don't error if the file...
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