From aafac6a6104b689a118f4c4f29f948d7d8a35aef Mon Sep 17 00:00:00 2001 From: Bill Glesias Date: Mon, 21 Oct 2024 15:26:40 -0400 Subject: [PATCH] chore: add graphql schema update and wrap process.kill to swallow esrch error [run ci] (#30434) --- packages/graphql/schemas/schema.graphql | 1 + packages/server/lib/browsers/firefox.ts | 26 +++++++++++++++++-- .../server/test/unit/browsers/firefox_spec.ts | 20 ++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/packages/graphql/schemas/schema.graphql b/packages/graphql/schemas/schema.graphql index 16e34c2a58a2..245a2e4a92cd 100644 --- a/packages/graphql/schemas/schema.graphql +++ b/packages/graphql/schemas/schema.graphql @@ -1201,6 +1201,7 @@ enum ErrorTypeEnum { EXPERIMENTAL_STUDIO_REMOVED EXPERIMENTAL_USE_DEFAULT_DOCUMENT_DOMAIN_E2E_ONLY EXTENSION_NOT_LOADED + FIREFOX_CDP_FAILED_TO_CONNECT FIREFOX_COULD_NOT_CONNECT FIREFOX_GC_INTERVAL_REMOVED FIREFOX_GECKODRIVER_FAILURE diff --git a/packages/server/lib/browsers/firefox.ts b/packages/server/lib/browsers/firefox.ts index cc5fc6ffdab2..d6215f7e488b 100644 --- a/packages/server/lib/browsers/firefox.ts +++ b/packages/server/lib/browsers/firefox.ts @@ -670,14 +670,36 @@ export async function open (browser: Browser, url: string, options: BrowserLaunc // now that we have the driverPID and browser PID browserInstanceWrapper.kill = (...args) => { // Do nothing on failure here since we're shutting down anyway + clearInstanceState({ gracefulShutdown: true }) debug('closing firefox') - const browserReturnStatus = process.kill(browserPID) + let browserReturnStatus = true + + try { + browserReturnStatus = process.kill(browserPID) + } catch (e) { + if (e.code === 'ESRCH') { + debugVerbose('browser process no longer exists. continuing...') + } else { + throw e + } + } debug('closing geckodriver and webdriver') - const driverReturnStatus = process.kill(driverPID) + + let driverReturnStatus = true + + try { + driverReturnStatus = process.kill(driverPID) + } catch (e) { + if (e.code === 'ESRCH') { + debugVerbose('geckodriver/webdriver process no longer exists. continuing...') + } else { + throw e + } + } // needed for closing the browser when switching browsers in open mode to signal // the browser is done closing diff --git a/packages/server/test/unit/browsers/firefox_spec.ts b/packages/server/test/unit/browsers/firefox_spec.ts index ead4d9bc83a8..18f0cb538c7b 100644 --- a/packages/server/test/unit/browsers/firefox_spec.ts +++ b/packages/server/test/unit/browsers/firefox_spec.ts @@ -606,6 +606,26 @@ describe('lib/browsers/firefox', () => { expect(instance.emit).to.have.been.calledWith('exit') }) + it('swallows ESRCH in kill method if thrown', async function () { + const ESRCHErr: Error & { code?: string } = new Error('BOOM') + + ESRCHErr.code = 'ESRCH' + sinon.stub(process, 'kill').throws(ESRCHErr) + const instance = await firefox.open(this.browser, 'http://', this.options, this.automation) + + sinon.spy(instance, 'emit') + const killResult = instance.kill() + + expect(killResult).to.be.true + // kills the browser + expect(process.kill).to.have.been.calledWith(1234) + // kills the webdriver process/ geckodriver process + expect(process.kill).to.have.been.calledWith(5678) + expect(browserCriClient.close).to.have.been.called + // makes sure the exit event is called to signal to the rest of cypress server that the processes are killed + expect(instance.emit).to.have.been.calledWith('exit') + }) + it('throws CDPFailedToStartFirefox if the mox:debuggerAddress capability is not returned by webdriver', function () { delete wdInstance.capabilities['moz:debuggerAddress'] sinon.stub(process, 'kill').returns(true)