Skip to content

feat(core): Log runtime names during Server shutdown #512

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
21 changes: 13 additions & 8 deletions pingora-core/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,12 @@ impl Server {
#[cfg(all(not(debug_assertions), feature = "sentry"))]
let _guard = self.sentry.as_ref().map(|opts| sentry::init(opts.clone()));

let mut runtimes: Vec<Runtime> = Vec::new();
// Holds tuples of runtimes and their service name.
let mut runtimes: Vec<(Runtime, String)> = Vec::new();

while let Some(service) = self.services.pop() {
let threads = service.threads().unwrap_or(conf.threads);
let name = service.name().to_string();
let runtime = Server::run_service(
service,
#[cfg(unix)]
Expand All @@ -347,7 +349,7 @@ impl Server {
threads,
conf.work_stealing,
);
runtimes.push(runtime);
runtimes.push((runtime, name));
}

// blocked on main loop so that it runs forever
Expand Down Expand Up @@ -379,20 +381,23 @@ impl Server {
.unwrap_or(5),
),
};
let shutdowns: Vec<_> = runtimes
let shutdowns: Vec<(_, String)> = runtimes
.into_iter()
.map(|rt| {
.map(|(rt, name)| {
info!("Waiting for runtimes to exit!");
thread::spawn(move || {
let join = thread::spawn(move || {
rt.shutdown_timeout(shutdown_timeout);
thread::sleep(shutdown_timeout)
})
});
(join, name)
})
.collect();
for shutdown in shutdowns {
for (shutdown, name) in shutdowns {
info!("Waiting for service runtime {} to exit", name);
if let Err(e) = shutdown.join() {
error!("Failed to shutdown runtime: {:?}", e);
error!("Failed to shutdown service runtime {}: {:?}", name, e);
}
debug!("Service runtime {} has exited", name);
}
info!("All runtimes exited, exiting now");
std::process::exit(0)
Expand Down
Loading