sebhildebrandt / systeminformation

System Information Library for Node.JS
MIT License
2.7k stars 307 forks source link

Linux/Darwin don't crash on spawn EBADF errors #913

Open reinismu opened 3 months ago

reinismu commented 3 months ago

When running on MacOS I notices that sometimes the call process spawn will crash

Error: spawn EBADF
    at ChildProcess.spawn (node:internal/child_process:421:11)
    at spawn (node:child_process:761:9)
    at Object.execFile (node:child_process:351:17)
    at exec (node:child_process:234:25)
    at /Users/xpresshd/projects/poker/node/ddr/node_modules/systeminformation/lib/filesystem.js:604:9
    at processTicksAndRejections (node:internal/process/task_queues:77:11) {
  errno: -9,
  code: 'EBADF',
  syscall: 'spawn'
}

I would like to handle it and not crash my nodejs process

sebhildebrandt commented 3 months ago

@reinismu ... I have two questions

reinismu commented 3 months ago

@sebhildebrandt I use node v20.11.1 and run my code with just node.

I have a long running process that calls blockDevices every second. This happens usually after 4-5 hours of running. maybe hitting ulimit. Invstigating now.

In any case I would like to handle that error

sebhildebrandt commented 3 months ago

@reinismu I agree, handling the error makes sense ... but then I would have to do it everywhere where we have exec ... and the handling needs to be a little bit different.

sebhildebrandt commented 3 months ago

@reinismu ... one more thing: running blockDevicesevery second is quite often ... this action takes at least 1-2 seconds, so I would extend the period ... and depending of the use case you have this could be even really long (or is it, that you want to detect changes like adding USB sticks, external SSDs...?)

I know. this might not solve the issue ... but still I would increase the poll interval.

reinismu commented 3 months ago

@sebhildebrandt Thanks for suggestions! Will do that. Working with a legacy system and don't want to rewrite it yet. 1-2 seconds execution time might explain how it run out of file descriptors.

Ye, all exec's would need this then. This mostly just solved issue for me. Opened a PR so if someone else gets a similar issue they would have some info on it.