Search code examples
node.jsasynchronousnonblockinglibuv

libuv uses blocking file system calls internally – Why? How?


I just learned that Node.js crown jewel libuv uses blocking system calls for file operations. The asynchronous behavior is implemented with threads! That raises two questions (I only care about Unix):

  1. Why is it not using the non-blocking filesystem calls like it does for networking?
  2. If there are one million outstanding file reads, it probably does not launch one million threads... What does libuv do??

Solution

    1. The same non-blocking API can not be used, as O_NONBLOCK and friends don’t work on regular files! For Linux AIO is available, but it has it’s own quirks (i.e. depends on the filesystem, turns silently blocking for some operations).

    2. I have no idea.