Skip to content

Commit

Permalink
fix: retry browser launch if it failed due to glibc error (#5247)
Browse files Browse the repository at this point in the history
Fixes #5214
  • Loading branch information
aslushnikov committed Feb 1, 2021
1 parent 198e403 commit 276bbca
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/server/browserType.ts
Expand Up @@ -66,7 +66,7 @@ export abstract class BrowserType {
const controller = new ProgressController();
controller.setLogName('browser');
const browser = await controller.run(progress => {
return this._innerLaunch(progress, options, undefined, helper.debugProtocolLogger(protocolLogger)).catch(e => { throw this._rewriteStartupError(e); });
return this._innerLaunchWithRetries(progress, options, undefined, helper.debugProtocolLogger(protocolLogger)).catch(e => { throw this._rewriteStartupError(e); });
}, TimeoutSettings.timeout(options));
return browser;
}
Expand All @@ -77,11 +77,25 @@ export abstract class BrowserType {
const controller = new ProgressController();
controller.setLogName('browser');
const browser = await controller.run(progress => {
return this._innerLaunch(progress, options, persistent, helper.debugProtocolLogger(), userDataDir).catch(e => { throw this._rewriteStartupError(e); });
return this._innerLaunchWithRetries(progress, options, persistent, helper.debugProtocolLogger(), userDataDir).catch(e => { throw this._rewriteStartupError(e); });
}, TimeoutSettings.timeout(options));
return browser._defaultContext!;
}

async _innerLaunchWithRetries(progress: Progress, options: types.LaunchOptions, persistent: types.BrowserContextOptions | undefined, protocolLogger: types.ProtocolLogger, userDataDir?: string): Promise<Browser> {
try {
return this._innerLaunch(progress, options, persistent, protocolLogger, userDataDir);
} catch (error) {
// @see https://github.com/microsoft/playwright/issues/5214
const errorMessage = typeof error === 'object' && typeof error.message === 'string' ? error.message : '';
if (errorMessage.includes('Inconsistency detected by ld.so')) {
progress.log(`<restarting browser due to hitting race condition in glibc>`);
return this._innerLaunch(progress, options, persistent, protocolLogger, userDataDir);
}
throw error;
}
}

async _innerLaunch(progress: Progress, options: types.LaunchOptions, persistent: types.BrowserContextOptions | undefined, protocolLogger: types.ProtocolLogger, userDataDir?: string): Promise<Browser> {
options.proxy = options.proxy ? normalizeProxySettings(options.proxy) : undefined;
const browserLogsCollector = new RecentLogsCollector();
Expand Down

0 comments on commit 276bbca

Please sign in to comment.