Wizcorp / node-graylog2

Graylog2 client library for Node.js
Other
58 stars 36 forks source link

zlib deflate results in a memory leak #19

Open jasonmcaffee opened 7 years ago

jasonmcaffee commented 7 years ago

This is a node issue, but your library uses zlib, and it causes a memory leak that has been crashing our docker containers on EC2. Unfortunately that means we can no longer use your library, and have to opt for another lib that doesn't use zlib.

It's really easy to recreate the issue:

let zlib = require('zlib');

let message = {
  some:"data"
};
let payload = new Buffer(JSON.stringify(message));

for(var i =0; i < 30000; ++i){
  zlib.deflate(payload, function (err, buffer) {
  });
}

setTimeout(()=>{}, 2000000);

Here's the related node issue: https://github.com/nodejs/node/issues/8871

ronkorving commented 7 years ago

It would be nice to make zlib optional through an option passed to the constructor. Wanna make a PR that does that?

jasonmcaffee commented 7 years ago

@ronkorving Unfortunately I don't have the time at the moment. It would be cool to allow for various compression types (deflate, gzip, et) as well as compression levels, similar to how docker does: https://docs.docker.com/engine/admin/logging/overview/#/gelf-options

Our quick fix is to have docker do the transporting, and removing the graylog transport from winston.

ronkorving commented 7 years ago

Graylog uses the GELF format for transporting its messages. It only supports gzip (deflate is gzip just without file headers afaik), so other formats are out of the question. GELF and compression: http://docs.graylog.org/en/2.1/pages/gelf.html#compression