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

PHD: improve ctrl-c handling #634

Merged
merged 4 commits into from
Feb 14, 2024
Merged

PHD: improve ctrl-c handling #634

merged 4 commits into from
Feb 14, 2024

Conversation

gjcolombo
Copy link
Contributor

(N.B. Depends on #633.)

Install a SIGINT handler in the PHD runner and use it to broadcast to all test execution tasks that this signal was received. Add a select! to the tasks to preempt further execution of test cases when this happens. Dropping the test case futures also drops all the VMs and disks they create, giving the runner a chance to clean up kernel VMMs and disk backing files before exiting. (If one SIGINT is handled and a second is received, exit immediately to allow the runner to be killed even if a test case hasn't reached an await point.)

To ensure that Propolis processes get a chance to stop gracefully, add a pre-exec hook so that the framework's Propolis servers ignore SIGINT. This is needed so that hitting Ctrl-C to interrupt a foreground runner doesn't take out the Propolis servers in the same process group before TestVm::drop gets a chance to clean them up.

Tested with runs of Debian 11 guests, both running to completion (all tests still pass) and interrupted at various points midway (verified that kernel VMMs and disks get cleaned up as expected when they didn't before).

@gjcolombo gjcolombo force-pushed the gjcolombo/phd/async branch from bd828df to 230a53a Compare February 7, 2024 17:24
@gjcolombo gjcolombo mentioned this pull request Feb 7, 2024
Base automatically changed from gjcolombo/phd/async to master February 7, 2024 19:19
@gjcolombo gjcolombo force-pushed the gjcolombo/phd/ctrl-c branch from 3baee13 to 9200778 Compare February 7, 2024 19:24
@gjcolombo gjcolombo requested a review from hawkw February 7, 2024 19:47
Copy link
Member

@hawkw hawkw left a comment

Choose a reason for hiding this comment

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

this looks good to me! i have one very small style nit to pick, but it's not as blocker.

Install a signal handler in the PHD runner that catches SIGINT and relays it via
`tokio::sync::watch` to any tasks that are currently executing tests. This
allows the test tasks to exit at the next available `await` point. Since these
tasks are themselves awaited before the runner exits, this ensures that all VMs
and disks created by a test can be dropped and cleaned up before the runner goes
away.

Ctrl-C characters sent to a shell will typically cause SIGINT to be sent to all
processes in the foreground process group. This is bad for PHD because any
Propolis servers the runner spawned will be killed before `TestVm::drop` gets a
chance to gracefully stop the VMs inside. Since dropping a `PropolisServer`
kills the process in any case, get around this by configuring PHD-spawned
Propolis servers to ignore SIGINT.

Tested with local Debian 11 runs, observing in particular that interrupting a
run with Ctrl-C does not leak any VMMs or temporary disk objects.
@gjcolombo gjcolombo force-pushed the gjcolombo/phd/ctrl-c branch from 13a27d1 to c655dfb Compare February 14, 2024 19:08
@gjcolombo gjcolombo merged commit aeb2339 into master Feb 14, 2024
10 checks passed
@gjcolombo gjcolombo deleted the gjcolombo/phd/ctrl-c branch February 14, 2024 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants