chore: improve debugging for EBUSY errors on Windows (#9976)

Co-authored-by: Nikolay Vitkov <34244704+Lightning00Blade@users.noreply.github.com>
This commit is contained in:
Alex Rudenko 2023-04-05 15:09:30 +02:00 committed by GitHub
parent 8222bc01b4
commit 0b2d988cc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 68 additions and 15 deletions

View File

@ -291,17 +291,16 @@ class Process {
) {
try {
if (process.platform === 'win32') {
childProcess.exec(
`taskkill /pid ${this.#browserProcess.pid} /T /F`,
error => {
if (error) {
// taskkill can fail to kill the process e.g. due to missing permissions.
// Let's kill the process via Node API. This delays killing of all child
// processes of `this.proc` until the main Node.js process dies.
this.#browserProcess.kill();
}
}
);
try {
childProcess.execSync(
`taskkill /pid ${this.#browserProcess.pid} /T /F`
);
} catch (error) {
// taskkill can fail to kill the process e.g. due to missing permissions.
// Let's kill the process via Node API. This delays killing of all child
// processes of `this.proc` until the main Node.js process dies.
this.#browserProcess.kill();
}
} else {
// on linux the process group can be killed with the group id prefixed with
// a minus sign. The process group id is the group leader's pid.

View File

@ -90,11 +90,36 @@ describe('Chrome', () => {
const process = launch({
executablePath,
args: [
'--allow-pre-commit-input',
'--disable-background-networking',
'--disable-background-timer-throttling',
'--disable-backgrounding-occluded-windows',
'--disable-breakpad',
'--disable-client-side-phishing-detection',
'--disable-component-extensions-with-background-pages',
'--disable-component-update',
'--disable-default-apps',
'--disable-dev-shm-usage',
'--disable-extensions',
'--disable-features=Translate,BackForwardCache,AcceptCHFrame,MediaRouter,OptimizationHints,DialMediaRouteProvider',
'--disable-hang-monitor',
'--disable-ipc-flooding-protection',
'--disable-popup-blocking',
'--disable-prompt-on-repost',
'--disable-renderer-backgrounding',
'--disable-sync',
'--enable-automation',
'--enable-features=NetworkServiceInProcess2',
'--export-tagged-pdf',
'--force-color-profile=srgb',
'--headless=new',
'--use-mock-keychain',
'--disable-features=DialMediaRouteProvider',
'--metrics-recording-only',
'--no-first-run',
'--password-store=basic',
'--remote-debugging-port=9222',
'--use-mock-keychain',
`--user-data-dir=${path.join(tmpDir, 'profile')}`,
'about:blank',
],
});
const url = await process.waitForLineOutput(CDP_WEBSOCKET_ENDPOINT_REGEX);

View File

@ -15,6 +15,7 @@
*/
import assert from 'assert';
import {execSync} from 'child_process';
import fs from 'fs';
import os from 'os';
import path from 'path';
@ -26,6 +27,7 @@ import {
Browser,
BrowserPlatform,
Cache,
createProfile,
} from '../../../lib/cjs/main.js';
import {testFirefoxBuildId} from '../versions.js';
@ -59,10 +61,37 @@ describe('Firefox', () => {
});
afterEach(() => {
new Cache(tmpDir).clear();
try {
new Cache(tmpDir).clear();
} catch (err) {
if (os.platform() === 'win32') {
console.log(execSync('tasklist').toString('utf-8'));
}
throw err;
}
});
it('should launch a Firefox browser', async () => {
const userDataDir = path.join(tmpDir, 'profile');
function getArgs(): string[] {
const firefoxArguments = ['--no-remote'];
switch (os.platform()) {
case 'darwin':
firefoxArguments.push('--foreground');
break;
case 'win32':
firefoxArguments.push('--wait-for-browser');
break;
}
firefoxArguments.push('--profile', userDataDir);
firefoxArguments.push('--headless');
firefoxArguments.push('about:blank');
return firefoxArguments;
}
await createProfile(Browser.FIREFOX, {
path: userDataDir,
preferences: {},
});
const executablePath = computeExecutablePath({
cacheDir: tmpDir,
browser: Browser.FIREFOX,
@ -70,7 +99,7 @@ describe('Firefox', () => {
});
const process = launch({
executablePath,
args: [`--user-data-dir=${path.join(tmpDir, 'profile')}`],
args: getArgs(),
});
await process.close();
});