Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(process launcher): use spawnSync to cleanup synchronously (#13769)

Dmitry Gozmandab2384b0eaf
diff --git a/packages/playwright-core/package.json b/packages/playwright-core/package.json
index 7ee76439aa..b1c37eac43 100644
--- a/packages/playwright-core/package.json
+++ b/packages/playwright-core/package.json
@@ -29,6 +29,7 @@
"./lib/utils/manualPromise": "./lib/utils/manualPromise.js",
"./lib/utils/multimap": "./lib/utils/multimap.js",
"./lib/utils/processLauncher": "./lib/utils/processLauncher.js",
+ "./lib/utils/processLauncherCleanupEntrypoint": "./lib/utils/processLauncherCleanupEntrypoint.js",
"./lib/utils/spawnAsync": "./lib/utils/spawnAsync.js",
"./lib/utils/stackTrace": "./lib/utils/stackTrace.js",
"./lib/utils/timeoutRunner": "./lib/utils/timeoutRunner.js",
diff --git a/packages/playwright-core/src/utils/processLauncher.ts b/packages/playwright-core/src/utils/processLauncher.ts
index 6d06a1be55..c2fa432848 100644
--- a/packages/playwright-core/src/utils/processLauncher.ts
+++ b/packages/playwright-core/src/utils/processLauncher.ts
@@ -17,10 +17,10 @@
import * as childProcess from 'child_process';
import * as readline from 'readline';
+import * as path from 'path';
import { eventsHelper } from './eventsHelper';
import { isUnderTest } from './';
import { removeFolders } from './fileUtils';
-import { rimraf } from '../utilsBundle';
export type Env = {[key: string]: string | number | boolean | undefined};
@@ -191,12 +191,13 @@ export async function launchProcess(options: LaunchProcessOptions): Promise<Laun
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}`);
- }
+ if (options.tempDirectories.length) {
+ const cleanupProcess = childProcess.spawnSync(process.argv0, [path.join(__dirname, 'processLauncherCleanupEntrypoint.js'), ...options.tempDirectories]);
+ const [stdout, stderr] = [cleanupProcess.stdout.toString(), cleanupProcess.stderr.toString()];
+ if (stdout)
+ options.log(`[pid=${spawnedProcess.pid || 'N/A'}] ${stdout}`);
+ if (stderr)
+ options.log(`[pid=${spawnedProcess.pid || 'N/A'}] ${stderr}`);
}
options.log(`[pid=${spawnedProcess.pid || 'N/A'}] finished temporary directories cleanup`);
}
diff --git a/packages/playwright-core/src/utils/processLauncherCleanupEntrypoint.ts b/packages/playwright-core/src/utils/processLauncherCleanupEntrypoint.ts
new file mode 100644
index 0000000000..e11c67f158
--- /dev/null
+++ b/packages/playwright-core/src/utils/processLauncherCleanupEntrypoint.ts
@@ -0,0 +1,28 @@
+/**
+ * Copyright (c) Microsoft Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { removeFolders } from './fileUtils';
+
+(async () => {
+ const dirs = process.argv.slice(2);
+ const errors = await removeFolders(dirs);
+ for (let i = 0; i < dirs.length; ++i) {
+ if (errors[i]) {
+ // eslint-disable-next-line no-console
+ console.error(`exception while removing ${dirs[i]}: ${errors[i]}`);
+ }
+ }
+})();