chore: sort out signal handling (#506)

This commit is contained in:
Pavel Feldman 2025-06-01 14:11:42 -07:00 committed by GitHub
parent f31ef598bc
commit 0b74cdaaf8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 2 deletions

View File

@ -98,7 +98,11 @@ class IsolatedContextFactory extends BaseContextFactory {
protected override async _doObtainBrowser(): Promise<playwright.Browser> { protected override async _doObtainBrowser(): Promise<playwright.Browser> {
const browserType = playwright[this.browserConfig.browserName]; const browserType = playwright[this.browserConfig.browserName];
return browserType.launch(this.browserConfig.launchOptions).catch(error => { return browserType.launch({
...this.browserConfig.launchOptions,
handleSIGINT: false,
handleSIGTERM: false,
}).catch(error => {
if (error.message.includes('Executable doesn\'t exist')) if (error.message.includes('Executable doesn\'t exist'))
throw new Error(`Browser specified in your config is not installed. Either install it (likely) or change the config.`); throw new Error(`Browser specified in your config is not installed. Either install it (likely) or change the config.`);
throw error; throw error;
@ -160,7 +164,12 @@ class PersistentContextFactory implements BrowserContextFactory {
const browserType = playwright[this.browserConfig.browserName]; const browserType = playwright[this.browserConfig.browserName];
for (let i = 0; i < 5; i++) { for (let i = 0; i < 5; i++) {
try { try {
const browserContext = await browserType.launchPersistentContext(userDataDir, { ...this.browserConfig.launchOptions, ...this.browserConfig.contextOptions }); const browserContext = await browserType.launchPersistentContext(userDataDir, {
...this.browserConfig.launchOptions,
...this.browserConfig.contextOptions,
handleSIGINT: false,
handleSIGTERM: false,
});
const close = () => this._closeBrowserContext(browserContext, userDataDir); const close = () => this._closeBrowserContext(browserContext, userDataDir);
return { browserContext, close }; return { browserContext, close };
} catch (error: any) { } catch (error: any) {

View File

@ -42,7 +42,11 @@ export class Server {
} }
setupExitWatchdog() { setupExitWatchdog() {
let isExiting = false;
const handleExit = async () => { const handleExit = async () => {
if (isExiting)
return;
isExiting = true;
setTimeout(() => process.exit(0), 15000); setTimeout(() => process.exit(0), 15000);
await Promise.all(this._connectionList.map(connection => connection.close())); await Promise.all(this._connectionList.map(connection => connection.close()));
process.exit(0); process.exit(0);