Skip to content

Commit 952c7d1

Browse files
committed
CLI: Wait for both the 'end' and 'close' event to happen before finishing in pbts, see protocolbuffers#863
1 parent 31ab863 commit 952c7d1

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

cli/pbts.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,15 @@ exports.main = function(args, callback) {
106106
maxBuffer: 1 << 24 // 16mb
107107
});
108108
var out = [];
109+
var ended = false;
110+
var closed = false;
109111
child.stdout.on("data", function(data) {
110112
out.push(data);
111113
});
114+
child.stdout.on("end", function() {
115+
if (closed) finish();
116+
else ended = true;
117+
});
112118
child.stderr.pipe(process.stderr);
113119
child.on("close", function(code) {
114120
// clean up temporary files, no matter what
@@ -123,6 +129,11 @@ exports.main = function(args, callback) {
123129
throw err;
124130
}
125131

132+
if (ended) finish();
133+
else closed = true;
134+
});
135+
136+
function finish() {
126137
var output = [];
127138
if (argv.global)
128139
output.push(
@@ -149,7 +160,7 @@ exports.main = function(args, callback) {
149160
return callback(err);
150161
throw err;
151162
}
152-
});
163+
}
153164
}
154165

155166
return undefined;

0 commit comments

Comments
 (0)