chris-rock / bunyan-logstash-tcp

logstash tcp module for bunyan
21 stars 21 forks source link

`clone` function will cause stack overflow #3

Closed rayshih closed 10 years ago

rayshih commented 10 years ago

For example:

var a = {};
var b = {};
a.b = b;
b.a = a;

logger.debug(a, 'will overflow');

This is the my current workaround:

var json = JSON.stringify(a, bunyan.safeCycles());
var obj = JSON.parse(json);

// time is a string after stringify
if (typeof obj.time === 'string')
  obj.time = new Date(obj.time);

logger.debug(obj, 'will be ok');

Any idea?

chris-rock commented 10 years ago

Yep, the internal clone method is not safe. We should switch to lodash cloneDeep: http://lodash.com/docs#cloneDeep

t = _.cloneDeep(a)
chris-rock commented 10 years ago

I pushed a patch on master. If you could test it with your environment, I am going to release a new version

rayshih commented 10 years ago

Thanks! I'll try this later. And will let you know the result.

jwoudenberg commented 10 years ago

Any follow up on this? We're running into this issue too and it's not so nice to have your application crash on its logging :).

chris-rock commented 10 years ago

latest version published on npm with the fix.

jwoudenberg commented 10 years ago

Thanks!