Node.js - Error: write EPIPE code: 'EPIPE

13,274

After few tests I found a bug and the error is caused by a too big file.

Share:
13,274

Related videos on Youtube

MeV
Author by

MeV

Updated on June 04, 2022

Comments

  • MeV
    MeV almost 2 years

    I keep getting EPIPE error, on stdin stream and I can't find a reason:

    This is my code:

    var checkFile = function(data, callback){
       var child_process = spawn('ffprobe', ['-print_format', 'json', '-show_format', 'pipe:0']);
    
       var stdInError = function(e) {
           console.log(e);
       }
       child_process.stdin.on('error', stdInError);
    
       var generalError = function() {
           console.log("general Error" + "\n");
       }
       child_process.on('error', generalError);
    
       child_process.stdout.on('data', function(data){
            console.log("data" + "\n");
            console.log(data);
            console.log("\n");
       });
    
       child_process.on('close', function(){
           console.log("close" + "\n");
       }
    
       var exit = function(){
           console.log("exit");
       }
       child_process.on('exit', exit);
    
       console.log("write" + "\n");
       child_process.stdin.write(data);
       child_process.stdin.end();
    };
    

    And this is my output:

    write
    
    data
    
    <Buffer 7b 0a 20 20 20 20 22 66 6f 72 6d 61 74 22 3a 20 7b 0a 20 20 20 20 20 20 20 20 22 66 69 6c 65 6e 61 6d 65 22 3a 20 22 70 69 70 65 3a 30 22 2c 0a 20 20 20 ...>
    
    data
    
    <Buffer 0a 7d 0a>
    
    { [Error: write EPIPE] code: 'EPIPE', errno: 'EPIPE', syscall: 'write' }
    
    exit
    close
    

    I cannot find a reason for this error, i have also tried to implement

    child_process.stderr.on('data', function (data) {
        //throw errors
        console.log('stderr: ' + data);
    });
    

    And every line printed from ffprobe (which is a software to check audio/video files specs) is marked as stderr. For example:

    stderr: ffprobe version 2.2.4 Copyright (c) 2007-2014 the FFmpeg developers built on Jul 2 2014 15:07:45 with Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn) configuration: --prefix=/usr/local/Cellar/ffmpeg/2.2.4 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample --enable-vda --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libxvid --enable-libfreetype --enable-libtheora --enable-libvorbis --enable-libvpx --enable-librtmp --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-aacenc --enable-libass --enable-ffplay --enable-libspeex --enable-libschroedinger --enable-libfdk-aac --enable-libopus --enable-frei0r --enable-libopenjpeg --extra-cflags='-I/usr/local/Cellar/openjpeg/1.5.1_1/include/openjpeg-1.5 ' libavutil 52. 66.100 / 52. 66.100

    stderr: libavcodec 55. 52.102 / 55. 52.102 libavformat 55. 33.100 / 55. 33.100 libavdevice 55. 10.100 / 55. 10.100 libavfilter 4. 2.100 / 4. 2.100 libavresample 1. 2. 0 / 1. 2. 0 libswscale 2. 5.102 / 2. 5.102 libswresample 0. 18.100 / 0. 18.100 libpostproc 52. 3.100 / 52. 3.100

  • MeV
    MeV almost 8 years
    In my case the file uploaded was too big and reducing the size of it prevented the error
  • d0rf47
    d0rf47 over 3 years
    wow I actually can't believe this I had the same issue lmao! thank you!
  • BalB
    BalB over 2 years
    Excuse me, what has to do file size with this? I'm getting the same erorr but, im just doinf the stdin.write command (with a short string there)