From 2e2e0ecfc83a083c110633b6c8a0541dd772daa5 Mon Sep 17 00:00:00 2001 From: Greg Michalec Date: Thu, 2 Apr 2015 11:53:36 -0700 Subject: [PATCH 1/2] fix race conditions --- lib/deps/graph.js | 4 +++- lib/graphviz.js | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/deps/graph.js b/lib/deps/graph.js index 362bc4c..10bbdfa 100644 --- a/lib/deps/graph.js +++ b/lib/deps/graph.js @@ -376,7 +376,9 @@ Graph.prototype.render = function(type_or_options, name_or_callback, errback) { graphviz.stderr.on('data', function(data) { err += data; }); - graphviz.on('exit', function(code) { + // Avoid race condition by listening for close instead of exit in newer node.js versions + var version = process.version.split('.')[1]; + graphviz.on(version < 8 ? 'exit' : 'close', function(code) { if(code !== 0) { if(errback) { errback(code, out, err) } } else { diff --git a/lib/graphviz.js b/lib/graphviz.js index ca2d4ef..edda593 100644 --- a/lib/graphviz.js +++ b/lib/graphviz.js @@ -51,7 +51,9 @@ function _parse(file, callback, errback) { err += data; }); graphviz.stdin.end(); - graphviz.on('exit', function(code) { + // Avoid race condition by listening for close instead of exit in newer node.js versions + var version = process.version.split('.')[1]; + graphviz.on(version < 8 ? 'exit' : 'close', function(code) { if(code !== 0 || __graph_eval === undefined) { if(errback) { errback(code, out, err); From 33b8fae1b3e56c221e01c573434ac3adb34eb73b Mon Sep 17 00:00:00 2001 From: Greg Michalec Date: Sun, 12 Apr 2015 10:51:48 -0700 Subject: [PATCH 2/2] move eval to exit callback --- lib/graphviz.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/graphviz.js b/lib/graphviz.js index edda593..9bfa30d 100644 --- a/lib/graphviz.js +++ b/lib/graphviz.js @@ -45,7 +45,6 @@ function _parse(file, callback, errback) { graphviz.stdout.on('data', function(data) { out += data; - eval(data.toString()); }); graphviz.stderr.on('data', function(data) { err += data; @@ -54,6 +53,7 @@ function _parse(file, callback, errback) { // Avoid race condition by listening for close instead of exit in newer node.js versions var version = process.version.split('.')[1]; graphviz.on(version < 8 ? 'exit' : 'close', function(code) { + eval(out); if(code !== 0 || __graph_eval === undefined) { if(errback) { errback(code, out, err);