Skip to content

Commit

Permalink
Merge pull request #154 from defendertx/feature/pid-check
Browse files Browse the repository at this point in the history
Check that process exists before assuming Chrome is running
  • Loading branch information
adieuadieu committed Aug 3, 2018
2 parents 07f9e4b + 4fc078c commit a005b00
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/lambda/src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs'
// import path from 'path'
import LambdaChromeLauncher from './launcher'
import { debug } from './utils'
import { debug, processExists } from './utils'
import DEFAULT_CHROME_FLAGS from './flags'

const DEVTOOLS_PORT = 9222
Expand All @@ -28,7 +28,7 @@ export default async function launch ({
} = {}) {
const chromeFlags = [...DEFAULT_CHROME_FLAGS, ...flags]

if (!chromeInstance) {
if (!chromeInstance || !processExists(chromeInstance.pid)) {
if (process.env.AWS_EXECUTION_ENV || forceLambdaLauncher) {
chromeInstance = new LambdaChromeLauncher({
chromePath,
Expand Down
15 changes: 15 additions & 0 deletions packages/lambda/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,18 @@ export function makeTempDir () {
.toString()
.trim()
}

/**
* Checks if a process currently exists by process id.
* @param pid number process id to check if exists
* @returns boolean true if process exists, false if otherwise
*/
export function processExists (pid) {
let exists = true
try {
process.kill(pid, 0)
} catch (error) {
exists = false
}
return exists
}

0 comments on commit a005b00

Please sign in to comment.