@samitouri / QOSami-HFS / commits / 093621df

improved problem with unreachable UNC paths by limiting number of pending requests per host #1115

Massimo Melina committed Nov 2, 2025 at 16:15 UTC 093621df4a4d6195ca0a5917515d6b0449eb9650
1 file changed +11 -3
src/util-files.ts
+11 -3
@@ -1,7 +1,7 @@
1 // This file is part of HFS - Copyright 2021-2023, Massimo Melina <a@rejetto.com> - License https://www.gnu.org/licenses/gpl-3.0.txt
2
3 import { access, mkdir, readFile, stat } from 'fs/promises'
4 -import { Promisable, try_, wait, isWindowsDrive, haveTimeout } from './cross'
4 +import { Promisable, try_, wait, isWindowsDrive, haveTimeout, splitAt } from './cross'
5 import { defineConfig } from './config'
6 import { createWriteStream, mkdirSync, watch, ftruncate } from 'fs'
7 import { basename, dirname } from 'path'
@@ -14,8 +14,16 @@ import unzipper from 'unzip-stream'
14
15 const fileTimeout = defineConfig('file_timeout', 3, x => x * 1000)
16
17 -export function statWithTimeout(path: string) {
18 - return haveTimeout(fileTimeout.compiled(), stat(path))
17 +// since nodejs' UV_THREADPOOL_SIZE is 4 by default, avoid using multiple slots for the same UNC host. This doesn't solve the problem but at least mitigates it.
18 +const uncStatWaiting = new Map<string, Promise<any>>()
19 +export async function statWithTimeout(path: string) {
20 + const uncHost = path.startsWith('\\\\') && splitAt('\\', path.slice(2))[0]
21 + if (uncHost)
22 + await uncStatWaiting.get(uncHost)
23 + const op = stat(path)
24 + if (uncHost)
25 + uncStatWaiting.set(uncHost, op.finally(() => uncStatWaiting.delete(uncHost)).catch(() => {}))
26 + return haveTimeout(fileTimeout.compiled(), op)
27 }
28
29 export async function isDirectory(path: string) {