Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions rust/crates/git-host/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,10 +426,15 @@ mod platform {
return Ok(());
}
let error = io::Error::last_os_error();
if error.raw_os_error() == Some(libc::ESRCH) {
return Ok(());
match error.raw_os_error() {
Some(libc::ESRCH) => Ok(()),
// No member accepted the signal: on macOS every member is a
// zombie its parent has not reaped yet, or a member belongs
// to another user. Nothing more can be sent either way, and
// `ProcessTree::terminate` waits until the members are gone.
Some(libc::EPERM) => Ok(()),
_ => Err(error),
}
Err(error)
}
pub fn has_live_processes(&self) -> io::Result<bool> {
// SAFETY: signal 0 only checks whether the group still has members.
Expand All @@ -439,7 +444,8 @@ mod platform {
let error = io::Error::last_os_error();
match error.raw_os_error() {
Some(libc::ESRCH) => Ok(false),
// A member exists but belongs to another user, so it is alive.
// A member exists that refuses signals: an unreaped zombie on
// macOS or another user's process. It counts until it is gone.
Some(libc::EPERM) => Ok(true),
_ => Err(error),
}
Expand Down
3 changes: 3 additions & 0 deletions rust/crates/platform-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ hosts = ["macos", "windows"]
lithe-git-host = { path = "../git-host" }
lithe-lsp-transport = { path = "../lsp-transport" }
lithe-platform = { path = "../platform" }

[target.'cfg(unix)'.dev-dependencies]
libc = "0.2"
57 changes: 57 additions & 0 deletions rust/crates/platform-tests/tests/platform/process_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,63 @@ fn a_unix_tree_ends_only_once_its_root_is_reaped() {
.expect("a reaped root no longer counts");
}

/// A group whose members have all exited but are not reaped yet is a normal
/// moment while a tree ends: the runtime a language server started can still
/// wait for its new parent to reap it after the root is gone. macOS refuses to
/// signal such a group (`EPERM`), and ending the tree must not report that as
/// a failure.
#[cfg(unix)]
#[test]
fn a_unix_tree_of_exited_unreaped_processes_ends_without_error() {
let Tree {
tree,
root,
output: _output,
_input,
} = spawn_tree(Mode::Hold);

tree.kill().expect("a running tree is killed");
wait_until_exited_unreaped(root.id());
tree.kill()
.expect("a tree whose processes all exited is killed again without error");

let root_exit = reap_in_background(root);
tree.terminate(DEADLINE)
.expect("the tree ends once its exited root is reaped");
let status = root_exit.recv_timeout(DEADLINE).expect("root reaped");
assert!(!status.success());
}

/// Waits until the child `process_id` has exited and leaves it unreaped, so it
/// stays a zombie member of its process group until its `Child` is waited on.
#[cfg(unix)]
fn wait_until_exited_unreaped(process_id: u32) {
let (sender, receiver) = mpsc::channel();
std::thread::spawn(move || loop {
// SAFETY: `info` is a valid out-parameter, and `WNOWAIT` leaves the
// child for its `Child` owner to reap.
let result = unsafe {
let mut info: libc::siginfo_t = std::mem::zeroed();
libc::waitid(
libc::P_PID,
process_id as libc::id_t,
&mut info,
libc::WEXITED | libc::WNOWAIT,
)
};
let error = std::io::Error::last_os_error();
if result != 0 && error.kind() == std::io::ErrorKind::Interrupted {
continue;
}
let _ = sender.send(if result == 0 { Ok(()) } else { Err(error) });
break;
});
receiver
.recv_timeout(DEADLINE)
.expect("the killed root exits")
.expect("wait for the root without reaping it");
}

#[cfg(windows)]
#[test]
fn dropping_a_process_tree_ends_it_like_a_crashed_host() {
Expand Down
Loading