Skip to content

Commit

Permalink
Do a better job handling errors on stdin
Browse files Browse the repository at this point in the history
Don't end() the input stream either. It's just a read stream and there's
no end() to it. Just pause it and let the user do with it what she may.
  • Loading branch information
chazmo03 authored and Nicolas Joyard committed Apr 30, 2016
1 parent 497d117 commit 1e99ed5
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions lib/ffprobe.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,20 +149,21 @@ module.exports = function(proto) {
var ffprobe = spawn(path, ['-show_streams', '-show_format'].concat(options, src));

if (input.isStream) {
// Ignore any errors on the input stream and stdin. These seem to be thrown
// occasionally just before ffprobe closes
ffprobe.stdin.on('error', function() {});
// Skip errors on stdin. These get thrown when ffprobe is complete and
// there seems to be no way hook in and close stdin before it throws.
ffprobe.stdin.on('error', function(err) {
if (['ECONNRESET', 'EPIPE'].indexOf(err.code) >= 0) {return;}
throw err;
});

// Once ffprobe's input stream closes, we can shut down the read stream
// Once ffprobe's input stream closes, we need no more data from the
// input
ffprobe.stdin.on('close', function() {
input.source.removeListener('error', callback);
input.source.on('error', function() {});
input.source.end();
input.source.pause();
input.source.unpipe(ffprobe.stdin);
});

input.source.pipe(ffprobe.stdin);
input.source.on('error', callback);
input.source.resume();
}

ffprobe.on('error', callback);
Expand Down

0 comments on commit 1e99ed5

Please sign in to comment.