Skip to content

Commit a005b00

Browse files
authored
Merge pull request #154 from defendertx/feature/pid-check
Check that process exists before assuming Chrome is running
2 parents 07f9e4b + 4fc078c commit a005b00

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

packages/lambda/src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from 'fs'
22
// import path from 'path'
33
import LambdaChromeLauncher from './launcher'
4-
import { debug } from './utils'
4+
import { debug, processExists } from './utils'
55
import DEFAULT_CHROME_FLAGS from './flags'
66

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

31-
if (!chromeInstance) {
31+
if (!chromeInstance || !processExists(chromeInstance.pid)) {
3232
if (process.env.AWS_EXECUTION_ENV || forceLambdaLauncher) {
3333
chromeInstance = new LambdaChromeLauncher({
3434
chromePath,

packages/lambda/src/utils.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,18 @@ export function makeTempDir () {
2424
.toString()
2525
.trim()
2626
}
27+
28+
/**
29+
* Checks if a process currently exists by process id.
30+
* @param pid number process id to check if exists
31+
* @returns boolean true if process exists, false if otherwise
32+
*/
33+
export function processExists (pid) {
34+
let exists = true
35+
try {
36+
process.kill(pid, 0)
37+
} catch (error) {
38+
exists = false
39+
}
40+
return exists
41+
}

0 commit comments

Comments
 (0)