From 287625782f9221922bb4571d33414b73fdbec49a Mon Sep 17 00:00:00 2001 From: Jesse Chan Date: Mon, 8 Mar 2021 15:38:10 +0800 Subject: [PATCH] server: DiskUsage: increase timeout to 5s --- server/models/DiskUsage.ts | 2 +- server/util/diskUsageUtil.ts | 19 +++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/server/models/DiskUsage.ts b/server/models/DiskUsage.ts index 5c9ac30c..5426a600 100644 --- a/server/models/DiskUsage.ts +++ b/server/models/DiskUsage.ts @@ -58,7 +58,7 @@ class DiskUsage extends (EventEmitter as new () => TypedEmitter return Promise.reject(new Error()); } - return diskUsage[process.platform as SupportedPlatform]() + return diskUsage[process.platform as SupportedPlatform](INTERVAL_UPDATE / 2) .then((disks) => { // Mountpoints with a very long path are unlikely to be useful. return disks.filter((disk) => typeof disk.target === 'string' && disk.target.length < 30); diff --git a/server/util/diskUsageUtil.ts b/server/util/diskUsageUtil.ts index 65c9886f..8e888d73 100644 --- a/server/util/diskUsageUtil.ts +++ b/server/util/diskUsageUtil.ts @@ -36,12 +36,11 @@ const filterMountPoint = (mountpoint: string) => { }; const MAX_BUFFER_SIZE = 65536; -const EXEC_TIMEOUT = 2000; -export const diskUsage: Readonly Promise>>> = { - linux: () => +export const diskUsage: Readonly Promise>>> = { + linux: (timeout) => spawnAsync('df', ['-T'], { maxBuffer: MAX_BUFFER_SIZE, - timeout: EXEC_TIMEOUT, + timeout: timeout, }).then((stdout) => stdout .trim() @@ -59,10 +58,10 @@ export const diskUsage: Readonly Promise + freebsd: (timeout) => spawnAsync('df', [], { maxBuffer: MAX_BUFFER_SIZE, - timeout: EXEC_TIMEOUT, + timeout: timeout, }).then((stdout) => stdout .trim() @@ -79,10 +78,10 @@ export const diskUsage: Readonly Promise + darwin: (timeout) => spawnAsync('df', ['-kl'], { maxBuffer: MAX_BUFFER_SIZE, - timeout: EXEC_TIMEOUT, + timeout: timeout, }).then((stdout) => stdout .trim() @@ -99,10 +98,10 @@ export const diskUsage: Readonly Promise + win32: (timeout) => spawnAsync('wmic', ['logicaldisk'], { maxBuffer: MAX_BUFFER_SIZE, - timeout: EXEC_TIMEOUT, + timeout: timeout, }).then((stdout) => stdout .trim()