diff --git a/src/server/processLauncher.ts b/src/server/processLauncher.ts index 6262b6194d..a8939be2bc 100644 --- a/src/server/processLauncher.ts +++ b/src/server/processLauncher.ts @@ -61,8 +61,6 @@ if (maxListeners !== 0) process.setMaxListeners(Math.max(maxListeners || 0, 100)); export async function launchProcess(options: LaunchProcessOptions): Promise { - const cleanup = () => removeFolders(options.tempDirectories); - const stdio: ('ignore' | 'pipe')[] = options.stdio === 'pipe' ? ['ignore', 'pipe', 'pipe', 'pipe', 'pipe'] : ['pipe', 'pipe', 'pipe']; options.log(` ${options.executablePath} ${options.args.join(' ')}`); const spawnedProcess = childProcess.spawn( @@ -79,6 +77,16 @@ export async function launchProcess(options: LaunchProcessOptions): Promise { + options.log(`[pid=${spawnedProcess.pid || 'N/A'}] starting temporary directories cleanup`); + const errors = await removeFolders(options.tempDirectories); + for (let i = 0; i < options.tempDirectories.length; ++i) { + if (errors[i]) + options.log(`[pid=${spawnedProcess.pid || 'N/A'}] exception while removing ${options.tempDirectories[i]}: ${errors[i]}`); + } + options.log(`[pid=${spawnedProcess.pid || 'N/A'}] finished temporary directories cleanup`); + }; + // Prevent Unhandled 'error' event. spawnedProcess.on('error', () => {}); diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 919ec8604b..5de864c371 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -154,13 +154,11 @@ export function createGuid(): string { return crypto.randomBytes(16).toString('hex'); } -export async function removeFolders(dirs: string[]) { - await Promise.all(dirs.map((dir: string) => { - return new Promise(fulfill => { +export async function removeFolders(dirs: string[]): Promise> { + return await Promise.all(dirs.map((dir: string) => { + return new Promise(fulfill => { removeFolder(dir, { maxBusyTries: 10 }, error => { - if (error) - console.error(error); // eslint-disable no-console - fulfill(); + fulfill(error); }); }); }));