From bd73f9a5acaca337e9ec84208f852866a8e2079d Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Wed, 24 May 2023 19:09:52 +0200 Subject: [PATCH] fix(logger): increase max listeners of file transports to 20 --- packages/logger/src/node.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/logger/src/node.ts b/packages/logger/src/node.ts index c7e231034512..5b5bd97c4d0d 100644 --- a/packages/logger/src/node.ts +++ b/packages/logger/src/node.ts @@ -9,6 +9,13 @@ import {WinstonLogger} from "./winston.js"; const DATE_PATTERN = "YYYY-MM-DD"; +/** + * Increase max listeners of file transports to prevent `MaxListenersExceededWarning` warnings. + * Each child logger (`logger.child`) adds a new listener. Setting a reasonable limit to still + * detect potential memory leaks. See https://github.com/ChainSafe/lodestar/issues/5529 for details. + */ +const FILE_TRANSPORT_MAX_LISTENERS = 20; + export type LoggerNodeOpts = { level: LogLevel; /** @@ -104,12 +111,12 @@ function getNodeLoggerTransports(opts: LoggerNodeOpts): winston.transport[] { handleExceptions: true, maxFiles: opts.file.dailyRotate, auditFile: path.join(path.dirname(filename), ".log_rotate_audit.json"), - }) + }).setMaxListeners(FILE_TRANSPORT_MAX_LISTENERS) : new winston.transports.File({ level: opts.file.level, filename: filename, handleExceptions: true, - }) + }).setMaxListeners(FILE_TRANSPORT_MAX_LISTENERS) ); }