Skip to content

Commit f4d90d3

Browse files
suofacebook-github-bot
authored andcommitted
remove our custom signal handlers (#385)
Summary: Pull Request resolved: #385 These need to be written quite carefully as they need to be async-signal-safe (no log, no printf, no malloc). Let's just not even try, and instead rely on the standard fb implementation which has been worked over forever. Normally `#[fbinit]` will do this on the main entry point, but because bootstrap_main is a Python entry point that we spawn via the ProcessAllocator we need to call `initFacebook` there as well. ghstack-source-id: 293873376 exported-using-ghexport Reviewed By: vidhyav, mariusae Differential Revision: D77565855 fbshipit-source-id: c5a5f6a3ec180879e4df3544303dcbbcb0ba2756
1 parent fd25d79 commit f4d90d3

File tree

4 files changed

+11
-32
lines changed

4 files changed

+11
-32
lines changed

hyperactor/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ hyperactor_macros = { version = "0.0.0", path = "../hyperactor_macros" }
3232
hyperactor_telemetry = { version = "0.0.0", path = "../hyperactor_telemetry" }
3333
inventory = "0.3.8"
3434
lazy_static = { version = "1.5", features = ["spin_no_std"], default-features = false }
35-
libc = "0.2.139"
3635
ndslice = { version = "0.0.0", path = "../ndslice" }
3736
nix = { version = "0.29.0", features = ["dir", "event", "hostname", "inotify", "ioctl", "mman", "mount", "net", "poll", "ptrace", "reboot", "resource", "sched", "signal", "term", "time", "user", "zerocopy"] }
3837
opentelemetry = "0.29"

hyperactor/src/init.rs

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -37,41 +37,10 @@ pub fn initialize(handle: tokio::runtime::Handle) {
3737

3838
panic_handler::set_panic_hook();
3939
hyperactor_telemetry::initialize_logging(ClockKind::default());
40-
#[cfg(target_os = "linux")]
41-
linux::initialize();
4240
}
4341

4442
/// Initialize the Hyperactor runtime using the current tokio runtime handle.
4543
pub fn initialize_with_current_runtime() {
4644
let handle = tokio::runtime::Handle::current();
4745
initialize(handle);
4846
}
49-
50-
#[cfg(target_os = "linux")]
51-
mod linux {
52-
use std::backtrace::Backtrace;
53-
54-
use nix::sys::signal::SigHandler;
55-
56-
pub(crate) fn initialize() {
57-
// Safety: Because I want to
58-
unsafe {
59-
extern "C" fn handle_fatal_signal(signo: libc::c_int) {
60-
let bt = Backtrace::force_capture();
61-
let signame = nix::sys::signal::Signal::try_from(signo).expect("unknown signal");
62-
tracing::error!("stacktrace"= %bt, "fatal signal {signo}:{signame} received");
63-
std::process::exit(1);
64-
}
65-
nix::sys::signal::signal(
66-
nix::sys::signal::SIGABRT,
67-
SigHandler::Handler(handle_fatal_signal),
68-
)
69-
.expect("unable to register signal handler");
70-
nix::sys::signal::signal(
71-
nix::sys::signal::SIGSEGV,
72-
SigHandler::Handler(handle_fatal_signal),
73-
)
74-
.expect("unable to register signal handler");
75-
}
76-
}
77-
}

monarch_hyperactor/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ anyhow = "1.0.98"
1212
async-trait = "0.1.86"
1313
bincode = "1.3.3"
1414
clap = { version = "4.5.38", features = ["derive", "env", "string", "unicode", "wrap_help"] }
15+
fbinit = { version = "0.2.0", git = "https://github.com/facebookexperimental/rust-shed.git", branch = "main" }
1516
hyperactor = { version = "0.0.0", path = "../hyperactor" }
1617
hyperactor_extension = { version = "0.0.0", path = "../hyperactor_extension" }
1718
hyperactor_mesh = { version = "0.0.0", path = "../hyperactor_mesh" }

monarch_hyperactor/src/bootstrap.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,18 @@ use pyo3::wrap_pyfunction;
2020
#[pyfunction]
2121
#[pyo3(signature = ())]
2222
pub fn bootstrap_main(py: Python) -> PyResult<Bound<PyAny>> {
23+
// SAFETY: this is a correct use of this function.
24+
let _ = unsafe {
25+
fbinit::perform_init();
26+
};
27+
2328
hyperactor::tracing::debug!("entering async bootstrap");
2429
pyo3_async_runtimes::tokio::future_into_py::<_, ()>(py, async move {
30+
// SAFETY:
31+
// - Only one of these is ever created.
32+
// - This is the entry point of this program, so this will be dropped when
33+
// no more FB C++ code is running.
34+
let _destroy_guard = unsafe { fbinit::DestroyGuard::new() };
2535
bootstrap_or_die().await;
2636
})
2737
}

0 commit comments

Comments
 (0)