Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Kill browser process when killing process group fails #8477

Merged
merged 1 commit into from Jun 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/node/BrowserRunner.ts
Expand Up @@ -195,15 +195,23 @@ export class BrowserRunner {
if (error) {
// taskkill can fail to kill the process e.g. due to missing permissions.
// Let's kill the process via Node API. This delays killing of all child
// proccesses of `this.proc` until the main Node.js process dies.
// processes of `this.proc` until the main Node.js process dies.
proc.kill();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jimmydief is SIGKILL missing there in an intentional way?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Kikobeats I had wondered the same. FYI @szuend who made the original change in #8352.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SIGKILL is not a thing on windows. So if I remember the Node.js documentation correctly a call to kill without any signal is equivalent to SIGKILL.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, thanks for clarifying.

I considered the kill logic enough important to be alive as a separate package:
http://npm.im/kill-process-group

I was wondering if puppeteer will accept it if I send a PR; happy to invite anyone interested as contributor of the repo.

}
});
} else {
// on linux the process group can be killed with the group id prefixed with
// a minus sign. The process group id is the group leader's pid.
const processGroupId = -this.proc.pid;
process.kill(processGroupId, 'SIGKILL');

try {
process.kill(processGroupId, 'SIGKILL');
} catch (error) {
// Killing the process group can fail due e.g. to missing permissions.
// Let's kill the process via Node API. This delays killing of all child
// processes of `this.proc` until the main Node.js process dies.
proc.kill('SIGKILL');
}
}
} catch (error) {
throw new Error(
Expand Down