question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

memory leak when using logger.configure({level:'info'});

See original GitHub issue

winston 3.3.3

memory leak when using logger.configure({level:‘info’});

sample code:

`const winston = require(“winston”) const logger = winston.createLogger({ level: ‘debug’, format: winston.format.combine( winston.format.timestamp(), winston.format.json(), ), transports: [new winston.transports.Console()], });

logger.configure({level:‘info’}); const msg = new Array(1000).fill(‘0123456789’).join(‘’); const log = () => { for (let t = 0; t < 100; t++) { logger.debug(msg); } const used = process.memoryUsage().heapUsed / 1024 / 1024; console.log(mem use: ${Math.round(used * 100) / 100} MB); }; setInterval(log, 200);`

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:4
  • Comments:5

github_iconTop GitHub Comments

1reaction
lewijicommented, Oct 20, 2021

Just tried out winston for a project that’s nearing production, and have had these crashes reported very recently, and just now narrowed it down to winston. Removing winston and reverting the logging back to previous fixes the problem.

<--- Last few GCs --->                                                                                                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                                                                                                              
[83393:0x6840ad0] 14573859 ms: Scavenge 4028.4 (4118.9) -> 4025.9 (4128.2) MB, 123.7 / 0.0 ms  (average mu = 0.750, current mu = 0.300) allocation failure                                                                                                                                                                                    
[83393:0x6840ad0] 14573939 ms: Scavenge 4037.5 (4128.2) -> 4034.2 (4131.4) MB, 60.5 / 0.0 ms  (average mu = 0.750, current mu = 0.300) allocation failure                                                                                                                                                                                     
[83393:0x6840ad0] 14578290 ms: Mark-sweep 4041.1 (4131.4) -> 4036.5 (4144.7) MB, 4334.4 / 0.1 ms  (average mu = 0.600, current mu = 0.114) allocation failure scavenge might not succeed                                                                                                                                                      
                                                                                                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                                                                              
<--- JS stacktrace --->                                                                                                                                                                                                                                                                                                                       
                                                                                                                                                                                                                                                                                                                                              
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory                                                                                                                                                                                                                                                             
 1: 0xafd010 node::Abort() [/home/ljp/.nvm/versions/node/v16.10.0/bin/node]                                                                                                                                                                                                                                                                   
 2: 0xa141fb node::FatalError(char const*, char const*) [/home/ljp/.nvm/versions/node/v16.10.0/bin/node]                                                                                                                                                                                                                                      
 3: 0xce746e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/home/ljp/.nvm/versions/node/v16.10.0/bin/node]                                                                                                                                                                                                          
 4: 0xce77e7 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/home/ljp/.nvm/versions/node/v16.10.0/bin/node]                                                                                                                                                                                            
 5: 0xeb5c85  [/home/ljp/.nvm/versions/node/v16.10.0/bin/node]                                                                                                                                                                                                                                                                                
 6: 0xec5401 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/home/ljp/.nvm/versions/node/v16.10.0/bin/node]                                                                                                                                                   
 7: 0xec7fae v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/home/ljp/.nvm/versions/node/v16.10.0/bin/node]                                                                                                                    
 8: 0xe899da v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [/home/ljp/.nvm/versions/node/v16.10.0/bin/node]                                                                                                                                                                 
 9: 0x11fea76 v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [/home/ljp/.nvm/versions/node/v16.10.0/bin/node]                                                                                                                                                                                   
10: 0x15e7fb9  [/home/ljp/.nvm/versions/node/v16.10.0/bin/node]                                                                                                                                                                                                                                                                               
error Command failed with signal "SIGABRT".                                                                                                                                                                                                                                                                                                   
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.                                                                                                                                                                                                                                                          
ERROR: "start:server" exited with 1.                                                                                                                                                                                                                                                                                                          
error Command failed with exit code 1.                                                                                                                                                                                                                                                                                                        
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.  

Fwiw, our implementation created a single logger like so:

import "dotenv/config";
import winston from "winston";

const isDevelopment = process.env.NODE_ENV === "development";

const config = {
    level: isDevelopment ? 'debug' : 'warn',
    format: winston.format.json(),
    defaultMeta: {service: `server-${process.env.ENV_NAME}`},
    transports: [
        new winston.transports.Console({
            format: winston.format.cli()
        }),
    ],
    levels: winston.config.npm.levels
};


export default () => {
    const logger = winston.createLogger(config);
    Object.freeze(config);
    return logger;
}

This logger instance is stored in the server’s redux store, and recalled anywhere the app needs to log via redux getState(). Same behaviour in our GCP test environments and local dev machines; after some time the process exits with a heap OOM error. Unsure if we’re supposed to be recycling the instance like this, or are meant to flush the logs periodically or something, but for now I’m just reverting until more info comes to light.

0reactions
jkarttunencommented, Dec 19, 2021

I’m seeing this in GCP environment too - seem like disabling one line that logs a (large) JSON causes this. As if the js object was retained, and not released.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can I stop java.util.logging from contributing to a memory leak?
Short of making Sun fix the Level implementation or changing your library to do away with its custom Level, the only way I...
Read more >
Memory leak in legacy logging · Issue #134724 · elastic/kibana
Prerequisites: Kibana v7.16.x or v7.17.x Kibana logging to a file with logging.dest configuration option or cli argument (default for APT ...
Read more >
Built-in logging module may lead to memory leak?
I'm using the python built-in logging module in a django project. Using dictConfig, the configuration in settings.py is like this:.
Read more >
3 Troubleshoot Memory Leaks - Java - Oracle Help Center
Obviously, your live set may go up and down, but if you see a steady increase over time, then you could have a...
Read more >
winstonjs/winston - Gitter
(node:26105) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 unpipe listeners added to [File]. Use emitter.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found