cristiammercado / node-disk-info

Node module to get disk information in Windows, Linux, Mac, FreeBSD & OpenBSD (works with Electron).
MIT License
58 stars 14 forks source link

Error · EPIPE: broken pipe, write #22

Open deliverymanager opened 3 years ago

deliverymanager commented 3 years ago

I am running this module periodically on NODE 14.4 and on Windows. Sometimes I get an unhandled error from the code: return execSync(command,{windowsHide: true, encoding: 'buffer'});

If possible this error should be handled and not crash the whole node server.

Ekristoffe commented 3 years ago

Interesting, do you have the full error log available ?

deliverymanager commented 3 years ago
Error EPIPE: broken pipe, write 
    internal/net.js:54:25 Socket._write
    _stream_writable.js:352:12 writeOrBuffer
    _stream_writable.js:303:10 Socket.Writable.write
    child_process.js:645:20 Object.execSync
    pkg/prelude/bootstrap.js:1507:30 Object.childProcess.execSync
    C:\snapshot\node-localserver\node_modules\@deliverymanager\node-disk-info\dist\utils\utils.js:45:32 Function.execute
    C:\snapshot\node-localserver\node_modules\@deliverymanager\node-disk-info\dist\platforms\windows.js:23:36 Function.run
    C:\snapshot\node-localserver\node_modules\@deliverymanager\node-disk-info\dist\index.js:89:44 Object.getDiskInfoSync
    C:\snapshot\node-localserver\info.js:98:26 saveLocalServerDataServer
    C:\snapshot\node-localserver\info.js:169:20 
    C:\snapshot\node-localserver\node_modules\bluebird\js\release\util.js:16:23 tryCatcher
    C:\snapshot\node-localserver\node_modules\bluebird\js\release\map.js:68:38 MappingPromiseArray._promiseFulfilled
    C:\snapshot\node-localserver\node_modules\bluebird\js\release\promise_array.js:115:31 MappingPromiseArray.<anonymous>
    C:\snapshot\node-localserver\node_modules\bluebird\js\release\promise_array.js:79:10 MappingPromiseArray.init
    C:\snapshot\node-localserver\node_modules\bluebird\js\release\map.js:37:10 MappingPromiseArray._asyncInit
    C:\snapshot\node-localserver\node_modules\bluebird\js\release\async.js:97:12 _drainQueueStep
deliverymanager commented 3 years ago

I have been using my fork but it is pretty much the same.

deliverymanager commented 3 years ago

I have tried adding the following, but I am not so sure it will work and I have no actual way of testing because it is a very random error that crashes the whole node app.

public static execute(command: string): Buffer {
        try {
            return execSync(command, { windowsHide: true, encoding: 'buffer' });
        } catch (err) {
            console.log('err', err);
            return Buffer.from('\r\r\n', 'utf8');
        }
    }
deliverymanager commented 3 years ago

You also forgot to place the windowsHide to your new chcp command

        return execSync('chcp', { windowsHide: true }).toString().split(':')[1].trim();
deliverymanager commented 3 years ago

I have more news on the

try {
            return execSync(command, { windowsHide: true, encoding: 'buffer' });
        } catch (err) {
            console.log('err', err);
            return Buffer.from('\r\r\n', 'utf8');
        }

IT DOES NOT WORK. execSync still crashes the node app giving the Error · EPIPE: broken pipe, write

Ekristoffe commented 3 years ago

Hello, unfortunately I am not able to reproduce the error you have. but could you try those solution:

Solution 1:

try {
    return execSync(command, {stdio: ['pipe', 'pipe', 'ignore'], windowsHide: true, encoding: 'buffer' });
} catch (err) {
    console.log('err', err);
    return Buffer.from('\r\r\n', 'utf8');
}

Solution 2:

try {
    return execSync(command, { stdio: ['pipe', 'pipe', process.stderr], windowsHide: true, encoding: 'buffer' });
} catch (err) {
    console.log('err', err);
    return Buffer.from('\r\r\n', 'utf8');
}

Is far as I know, stdio is : stdin, stdout, and stderr By making stderr to ignore the pipe error may go away and you should have the error in the console. By making stderr to process.stderr the catch may work better ...

Ekristoffe commented 3 years ago

@deliverymanager any news about this problem ?