-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[Heartbeat] Use prctl to ensure subprocesses are cleaned up on exit #32393
Conversation
Pinging @elastic/uptime (Team:Uptime) |
60e2448
to
9f490c7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, tested E2E with Fleet integrations.
@andrewvc I've E2E tested this PR and it still didn't kill the Node processes (I'm using an x64 Mac btw) I tested it by updating my monitor so that it would run for a long time: heartbeat.monitors:
- type: browser
id: exits-monitor-3
name: exits-monitor-3
schedule: '@every 10s'
source:
inline:
script: |-
step("second", async () => {
await page.waitForTimeout(100_000)
await page.goto('https://www.google.com');
});
step("second", async () => {
await page.goto('https://www.bbc.co.uk');
}); Then, I verified I did have node processes spawned by Heartbeat, killed Heartbeat, and verified whether there were any node processes hanging (see image below). Did I do anything wrong with regards to testing or should I open an issue for this? |
@lucasfcosta sorry if it was unclear, but this is expected! This relies on linux specific behavior, so it won't work on other platforms. It's fine, however, in that synthetics only really needs to work on linux since it requires a linux container. The meat of the PR is in https://github.com/elastic/beats/blob/main/x-pack/heartbeat/monitors/browser/synthexec/synthexec_linux.go , note the |
The easiest way to test this, I should add, would be to check out the synthetics demo repo, modify https://github.com/elastic/synthetics-demo/blob/main/heartbeat/run.sh to set I think that should work. I tested it myself on my own linux WSL box. |
@andrewvc indeed that solved the problem! Here's the script I used to run it: #!/bin/bash -e
LATEST_RELEASE_TAG="8.4.0-SNAPSHOT"
DOCKER_IMAGE=docker.elastic.co/beats/heartbeat:$LATEST_RELEASE_TAG
echo "Using docker image $DOCKER_IMAGE"
docker run \
-it \
--entrypoint=/bin/bash \
--rm \
--name=heartbeat \
--user=heartbeat \
--net=elastic-package-stack_default \
--volume="/tmp/hb1.yml:/usr/share/heartbeat/heartbeat.yml:ro" \
$DOCKER_IMAGE Once I ran that script, I started heartbeat with |
…32393) Fixes #32363 by instructing the linux kernel to automatically kill node subprocesses if their parents die. In testing it appears chromium always dies as well, although I'm not entirely sure why. Either chrome sets the right flags itself, or the death signal propagates. Either way, in testing this works very solidly. We don't have sufficient automated test infrastructure to write a good automated test here, so this will have to reply on manual testing.
Fixes #32363 by instructing the linux kernel to automatically kill node subprocesses if their parents die. In testing it appears chromium always dies as well, although I'm not entirely sure why. Either chrome sets the right flags itself, or the death signal propagates. Either way, in testing this works very solidly.
We don't have sufficient automated test infrastructure to write a good automated test here, so this will have to reply on manual testing.
Checklist
CHANGELOG.next.asciidoc
orCHANGELOG-developer.next.asciidoc
.How to test this PR locally
Run the below heartbeat inline yaml, this journey will hang for a long time, giving you chrome / node processes that last for a long while. Once it is started, run
pkill heartbeat
which should kill heartbeat and all subprocesses. On themain
branch heartbeat and chromium will die, andnode
will persiste.