Skip to content

Commit

Permalink
fix: issue where process was exiting when window was being closed whi…
Browse files Browse the repository at this point in the history
…le launch process was occuring
  • Loading branch information
AtofStryker committed Jun 29, 2023
1 parent c1cc228 commit e0ef3b6
Showing 1 changed file with 29 additions and 15 deletions.
44 changes: 29 additions & 15 deletions packages/server/lib/browsers/electron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,25 +159,39 @@ export = {
}
},
async onNewWindow (this: BrowserWindow, e, url) {
const _win = this
let _win: BrowserWindow | null = this

const child = await _this._launchChild(e, url, _win, projectRoot, state, options, automation)

// close child on parent close
_win.on('close', () => {
if (!child.isDestroyed()) {
child.destroy()
}
_win.on('closed', () => {
// in some cases, the browser/test will close before _launchChild completes, leaving a destroyed/stale window object.
// in these cases, we want to proceed to the next test/open window without critically failing
_win = null
})

// add this pid to list of pids
tryToCall(child, () => {
if (instance && instance.pid) {
if (!instance.allPids) throw new Error('Missing allPids!')

instance.allPids.push(child.webContents.getOSProcessId())
try {
const child = await _this._launchChild(e, url, _win, projectRoot, state, options, automation)

// close child on parent close
_win.on('close', () => {
if (!child.isDestroyed()) {
child.destroy()
}
})

// add this pid to list of pids
tryToCall(child, () => {
if (instance && instance.pid) {
if (!instance.allPids) throw new Error('Missing allPids!')

instance.allPids.push(child.webContents.getOSProcessId())
}
})
} catch (e) {
if (_win === null) {
debug(`The window was closed while launching the child process. This usually means the browser or test errored before fully completing the launch process. Cypress will proceed to the next test`)
} else {
throw e
}
})
}
},
}

Expand Down

0 comments on commit e0ef3b6

Please sign in to comment.