Node crash with ERR_STREAM_DESTROYED when rotating logs
See original GitHub issueI was using a simple file transport in my server.
new winston.transports.File({ filename: C.DEFAULT_LOG_FILENAME })
That has been working fine throughout development. Now that I’m going to production, I added winston-daily-rotate-file, so I replaced the File transport listed above with this:
new winston.transports.DailyRotateFile({
filename : C.DEFAULT_LOG_FILENAME + '-%DATE%.log',
dirname : './logs',
datePattern : 'YYYY-MM-DD:HH',
zippedArchive : false,
maxSize : '2m',
maxFiles : '14d',
})
But I found that my node server was crashing. Turns out it was crashing when it hit the file size limit and rotated log files. I changed the maxSize to “4k” and was able to get it to crash easily by generating log data. Here is the message from the crash:
Error [ERR_STREAM_DESTROYED]: Cannot call write after a stream was destroyed
at doWrite (_stream_writable.js:406:19)
at clearBuffer (_stream_writable.js:517:5)
at onwrite (_stream_writable.js:465:7)
at fs.write (fs.js:2282:5)
at FSReqWrap.wrapper [as oncomplete] (fs.js:643:5)
I’m running node version is 10.3.0 on macOS 10.13.5. I’m new to node / winston, so its not clear to me if this is my problem, a problem in node, or a problem in winston.
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Error [ERR_STREAM_DESTROYED]: Cannot call write after a ...
It worked locally, but when it got to aws, the error happened because node is running as user 'webapp'. It looks like that...
Read more >Worker failures from stream write contention - GenieACS Forum
This happens to me on current master builds as well. Smells like a state management bug (trying to write to a socket that...
Read more >Let It Crash: Best Practices for Handling Node.js Errors on ...
When an error occurred, there was often not enough visibility on why it happened, a lack of logging details, and bouts of downtime...
Read more >Node.js v12.1.0 Documentation - Index of
Because printing to the console is an asynchronous operation, console.log() will cause the AsyncHooks callbacks to be called. Using console.log() or similar ...
Read more >Error [ERR_STREAM_DESTROYED] - Node-RED Forum
Error connecting to dbus: Error [ERR_STREAM_DESTROYED]: Cannot call ... Can i assume node-red is being crashed and the error in the log is ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
To anyone it may help: I got this error when I ran my app initially with
sudo
(meaning that logs would be written asroot:root
), then again withoutsudo
(meaning that logs would be written asubuntu:ubuntu
, and thus lacked privileges to rotate the logs).So in my case, it wasn’t a fault of Winston. Just a standard consequence of permissions management. To avoid it, always run the app as a user in the same usergroup as you intend to run it with in future.
I’m moving this issue to #226, which more accurately describes the problem (
winston-daily-rotate-file
does not work well with process managers).