Description
- Version: 4.4.3 and 5.10.1
- Platform: Linux 3.19.0-42-generic Improve repo description #48~14.04.1-Ubuntu SMP Fri Dec 18 10:24:49 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux (inside an LXC container)
- Subsystem: os
When running inside an LXC container with cgroups setup to restrict cpuset.cpus to something less than the number of CPUs in the host machine (very common with cloud providers), accessing os.cpus() will give the following:
node: ../deps/uv/src/unix/linux-core.c:746: read_times: Assertion `num == numcpus' failed.
Aborted
To reproduce you will need to run node inside an LXC container with the appropriate cpuset.cpus setting. You can then reproduce with this command:
node -e "var cpuCount = require('os').cpus().length;"
Because it triggers an assertion failure with an an abort it can't be caught in a try/catch in JavaScript and there really isn't a way to know if it will fail prior to calling it. A common use case for this would be getting the CPU count to use with the cluster module to determine how many instances to run.
While it may not be possible to address the underlying issue it would be helpful it if failed in a way that could be caught in a try/catch so code could be written to use sensible defaults or an alternative method in the event of failure.