fix(cleanup): use rimraf.sync on process exit (#9862)
Currently we call async `removeFolders` from a synchronous
`process.on('exit')` handler, which should not work.
This commit is contained in:
parent
1886897e5c
commit
e8c512dbeb
|
|
@ -19,6 +19,7 @@ import * as childProcess from 'child_process';
|
||||||
import * as readline from 'readline';
|
import * as readline from 'readline';
|
||||||
import { eventsHelper } from './eventsHelper';
|
import { eventsHelper } from './eventsHelper';
|
||||||
import { isUnderTest, removeFolders } from './utils';
|
import { isUnderTest, removeFolders } from './utils';
|
||||||
|
import rimraf from 'rimraf';
|
||||||
|
|
||||||
export type Env = {[key: string]: string | number | boolean | undefined};
|
export type Env = {[key: string]: string | number | boolean | undefined};
|
||||||
|
|
||||||
|
|
@ -124,7 +125,7 @@ export async function launchProcess(options: LaunchProcessOptions): Promise<Laun
|
||||||
cleanup().then(fulfillCleanup);
|
cleanup().then(fulfillCleanup);
|
||||||
});
|
});
|
||||||
|
|
||||||
const listeners = [ eventsHelper.addEventListener(process, 'exit', killProcess) ];
|
const listeners = [ eventsHelper.addEventListener(process, 'exit', killProcessAndCleanup) ];
|
||||||
if (options.handleSIGINT) {
|
if (options.handleSIGINT) {
|
||||||
listeners.push(eventsHelper.addEventListener(process, 'SIGINT', () => {
|
listeners.push(eventsHelper.addEventListener(process, 'SIGINT', () => {
|
||||||
gracefullyClose().then(() => {
|
gracefullyClose().then(() => {
|
||||||
|
|
@ -183,7 +184,19 @@ export async function launchProcess(options: LaunchProcessOptions): Promise<Laun
|
||||||
} else {
|
} else {
|
||||||
options.log(`[pid=${spawnedProcess.pid}] <skipped force kill spawnedProcess.killed=${spawnedProcess.killed} processClosed=${processClosed}>`);
|
options.log(`[pid=${spawnedProcess.pid}] <skipped force kill spawnedProcess.killed=${spawnedProcess.killed} processClosed=${processClosed}>`);
|
||||||
}
|
}
|
||||||
cleanup();
|
}
|
||||||
|
|
||||||
|
function killProcessAndCleanup() {
|
||||||
|
killProcess();
|
||||||
|
options.log(`[pid=${spawnedProcess.pid || 'N/A'}] starting temporary directories cleanup`);
|
||||||
|
for (const dir of options.tempDirectories) {
|
||||||
|
try {
|
||||||
|
rimraf.sync(dir, { maxBusyTries: 10 });
|
||||||
|
} catch (e) {
|
||||||
|
options.log(`[pid=${spawnedProcess.pid || 'N/A'}] exception while removing ${dir}: ${e}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
options.log(`[pid=${spawnedProcess.pid || 'N/A'}] finished temporary directories cleanup`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function killAndWait() {
|
function killAndWait() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue