Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Leaking disk space during rotation #2298

Open
dbas-dn opened this issue Apr 17, 2023 · 1 comment
Open

[Bug]: Leaking disk space during rotation #2298

dbas-dn opened this issue Apr 17, 2023 · 1 comment

Comments

@dbas-dn
Copy link

dbas-dn commented Apr 17, 2023

🔎 Search Terms

Descriptors to deleted files

The problem

Descriptors for already deleted files are not released with intensive logging and standard rotation, which causes a disk space leak.

What version of Winston presents the issue?

v3.8.2

What version of Node are you using?

v18.12.1

If this worked in a previous version of Winston, which was it?

No response

Minimum Working Example

'use strict';

const MAX_SIZE = 2000;
const MAX_FILES = 3;
const TIMEOUT_MS = 100;

const winston = require('winston');
const {format} = require('logform');
const path = require('path');
const {combine, timestamp, json} = format;

// Set up file transport - I assume logs folder exists
const logsDir = path.resolve(process.cwd(), './logs');
const filePath = path.join(logsDir, 'example.log');
const fileTransport = {
  tailable: true,
  maxsize: MAX_SIZE,
  maxFiles: MAX_FILES,
  filename: filePath,
  handleExceptions: false,
  level: 'debug',
};
fileTransport.format = combine(
  timestamp({format: 'YYYY-MM-DD HH:mm:ss.SSS'}),
  json(),
);

// Create logger with file transport
const logger = winston.createLogger({
  transports: [new winston.transports.File(fileTransport)],
  exitOnError: false,
});
logger.log('info', 'Created file logger');

// Add periodic logs so that files are rotated
let i = 0;
function timeoutLogger() {
  i++;
  logger.log('info', 'another log message ' + i);
  logger.log('error', 'error message ' + i);
  logger.log('http', 'http log message ' + i);
  logger.log('verbose', 'verbose log message ' + i);
  logger.log('debug', 'debug log message ' + i);
}
setInterval(timeoutLogger, TIMEOUT_MS);

Running the test

node --trace-warnings example.js
(node:272) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 31 end listeners added to [PassThrough]. Use emitter.setMaxListeners() to increase limit
    at _addListener (node:events:587:17)
    at PassThrough.addListener (node:events:605:10)
    at Readable.on (/test/node_modules/readable-stream/lib/_stream_readable.js:745:33)
    at PassThrough.once (node:events:649:8)
    at Readable.pipe (/test/node_modules/readable-stream/lib/_stream_readable.js:583:58)
    at WriteStream.<anonymous> (/test/node_modules/winston/lib/winston/transports/file.js:553:16)
    at WriteStream.emit (node:events:513:28)
    at node:internal/fs/streams:75:16
    at FSReqCallback.oncomplete (node:fs:197:23)

List running processes

# ps -ef
PID   USER     TIME  COMMAND
  272 root      0:00 node --trace-warnings example.js.  
....

Show unreleased FDs

# ls -l /proc/272/fd/ | grep deleted
l-wx------    1 root     root            64 Apr 12 11:04 20 -> /test/logs/example2.log (deleted)
l-wx------    1 root     root            64 Apr 12 11:04 21 -> /test/logs/example2.log (deleted)
l-wx------    1 root     root            64 Apr 12 11:04 22 -> /test/logs/example2.log (deleted)
l-wx------    1 root     root            64 Apr 12 11:04 23 -> /test/logs/example2.log (deleted)
l-wx------    1 root     root            64 Apr 12 11:04 24 -> /test/logs/example2.log (deleted)
l-wx------    1 root     root            64 Apr 12 11:04 25 -> /test/logs/example2.log (deleted)
l-wx------    1 root     root            64 Apr 12 11:04 26 -> /test/logs/example2.log (deleted)
l-wx------    1 root     root            64 Apr 12 11:13 27 -> /test/logs/example2.log (deleted)
l-wx------    1 root     root            64 Apr 12 11:13 28 -> /test/logs/example2.log (deleted)
l-wx------    1 root     root            64 Apr 12 11:13 29 -> /test/logs/example2.log (deleted)
....

Additional information

No response

@wbt
Copy link
Contributor

wbt commented Apr 17, 2023

Duplicate of #2100?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants