winstonjs / winston

A logger for just about everything.
http://github.com/winstonjs/winston
MIT License
22.84k stars 1.81k forks source link

heap goes out of memory #1624

Open ashuSvirus opened 5 years ago

ashuSvirus commented 5 years ago

Please tell us about your environment:

What is the problem?

I am using elastic-apm to view the system.process.memory.rss.bytes

After some time it goes over 1 GB and node application crashes with following error.

Steps to reproduce:

logger.js


'use strict';
/**
* This module implements the logger
*/

const DailyRotateFile = require('winston-daily-rotate-file'); const path = require('path'); const { createLogger, format, transports } = require('winston'); const { combine, timestamp, label, errors, json } = format; const pathJoin = path.join; const errorFileName = error.log'; const infoFileName = 'info.log';

// // - Write to all logs with level info and below to ~info.log // - Write all logs error (and below) to ~error.log. // const fileLogging = [ new DailyRotateFile({ level: 'error', filename: errorFileName, zippedArchive: false, handleExceptions: true }), new DailyRotateFile({ level: 'info', filename: infoFileName, zippedArchive: false, handleExceptions: true }) ] const logger = caller => { return createLogger({ level: 'info', format: combine( timestamp(), errors({ stack: true }), json() ), defaultMeta: {
origin: caller }, transports: [ ...fileLogging ] }); };

class Logger{ constructor (fileName) { this.filename = fileName; this.stream = { write: function(message){ logger(this.filename).info(message); } } } debug (msg, obj) { logger(this.filename).debug(msg, obj); } info (msg, obj){ logger(this.filename).info(msg, obj); } infoDebug (msg, obj) { logger(this.filename).debug(msg, obj); logger(this.filename).info(msg, obj); } warn (msg, obj) { logger(this.filename).warn(msg, obj); } error (msg, obj) { logger(this.filename).error(msg, obj); } } / How to import

Stack trace

<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 0x1727b525501 <JSObject>
   1: from [buffer.js:~187] [pc=0x3ffa8515ba7d](this=0xb59837bc219 <JSFunction Buffer (sfi = 0x1727b57d7b1)>,value=0x1bc83113a451 <Very long string[287111]>,encodingOrOffset=0x1727b534ea9 <String[4]: utf8>,length=0x3999cba022d1 <undefined>)
   2: arguments adaptor frame: 2->3
   3: send [/code/node_modules/express/lib/response.js:189] [bytecode=0x1456b5ead069 offset=510](this=...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
1: node::Abort() [node]
2: 0x11f155c [node]
3: v8::Utils::ReportOOMFailure(char const*, bool) [node]
4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [node]
5: v8::internal::Factory::NewRawTwoByteString(int, v8::internal::PretenureFlag) [node]
6: v8::internal::String::SlowFlatten(v8::internal::Handle<v8::internal::ConsString>, v8::internal::PretenureFlag) [node]
7: v8::internal::String::Flatten(v8::internal::Handle<v8::internal::String>, v8::internal::PretenureFlag) [node]
8: v8::String::WriteUtf8(char*, int, int*, int) const [node]
9: node::StringBytes::Write(v8::Isolate*, char*, unsigned long, v8::Local<v8::Value>, node::encoding, int*) [node]
10: node::Buffer::New(v8::Isolate*, v8::Local<v8::String>, node::encoding) [node]
11: 0x1211364 [node]
12: 0x3ffa842555e7
Aborted (core dumped)
Jokero commented 3 years ago

@ashuSvirus Have you solved the issue?

atsybulkoUp commented 1 year ago

was it changed only for log.error or should be available with info and debug as well? got the same OOM with large object in log.info

wbt commented 12 months ago

Possibly related, maybe duplicating: https://github.com/winstonjs/winston/issues/2237