If the name of the dir to be created is invalid, fs.mkdir never calls back and fs.mkdirSync blocks:
const fs = require('fs')
console.log("1")
fs.mkdir('invalid1:', {recursive: true}, (err) => {
console.log("is not called")
if (err) throw err
})
console.log("2")
fs.mkdirSync('invalid2:', {recursive: true})
console.log("is not reached")
BTW, the error message that is reported with {recursive: false} appears a bit strange:
Error: ENOENT: no such file or directory, mkdir 'invalid2:'
Wouldn't it be more convenient to use EPERM, EACCES or ENOTDIR?
Colons on NTFS files systems on Windows denote file streams (source).
The error is the same for "invalid>", "invalid<" oder "invalid|".
Yes - I know this module. However, it is not cross plattform as far as I can tell - ':', '<', '>','|' may be valid on Linux (although not necessarily recommended, I guess). Yes, of course I could distinguish platforms. But I could as well rely on "fs.mkdir" to fail, if something is wrong.
The point is, Node should, if it fails to create the directory for whatever reason, give a reasonable error and, of course, not hang - with { recursive: true } or not.
This is similar to https://github.com/nodejs/node/issues/27198, which was fixed by https://github.com/nodejs/node/pull/27207.
For invalid filenames, uv_fs_mkdir returns UV_ENOENT, which confuses the fs.mkdir function. It constantly creates the parent directory then tries to create the invalid folder.
Made a libuv PR that makes it return UV_EINVAL for invalid filenames. This fixes this issue.