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

heap goes out of memory #1624

Open
ashuSvirus opened this issue Mar 27, 2019 · 3 comments
Open

heap goes out of memory #1624

ashuSvirus opened this issue Mar 27, 2019 · 3 comments

Comments

@ashuSvirus
Copy link

ashuSvirus commented Mar 27, 2019

Please tell us about your environment:

  • winston version?
    • [+] winston@3
  • node -v outputs: 9.4.0
  • Operating System? (Windows, macOS, or Linux) Linux
  • Language? (all | TypeScript X.X | ES6/7 | ES5 | Dart) ES6

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
  * const logger = require('path-to-this-modeule)(__filename)
  * `__filename` is used to add the location where the logger was called/logged/raised
 */
const logFn = (...args) => new Logger(...args)
module.exports = logFn;

###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
Copy link

Jokero commented Nov 25, 2020

@ashuSvirus Have you solved the issue?

@atsybulkoUp
Copy link

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
Copy link
Contributor

wbt commented Nov 8, 2023

Possibly related, maybe duplicating: #2237

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

No branches or pull requests

4 participants