Skip to content

Commit be31479

Browse files
committed
feat(core): Log runtime names during Server shutdown
Log the names of runtimes during Server shutdown. Motivation: server shutdown can take quite a long time if the runtimes don't exit. It's hard to debug why this is the case, because there is no indiciation in the logs which service is pending. This small change modifies the server to log the name of the service whose runtime is being waited for.
1 parent 42e11c4 commit be31479

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

pingora-core/src/server/mod.rs

+13-8
Original file line numberDiff line numberDiff line change
@@ -335,10 +335,12 @@ impl Server {
335335
#[cfg(all(not(debug_assertions), feature = "sentry"))]
336336
let _guard = self.sentry.as_ref().map(|opts| sentry::init(opts.clone()));
337337

338-
let mut runtimes: Vec<Runtime> = Vec::new();
338+
// Holds a tuple of runtimes and the service name.
339+
let mut runtimes: Vec<(Runtime, String)> = Vec::new();
339340

340341
while let Some(service) = self.services.pop() {
341342
let threads = service.threads().unwrap_or(conf.threads);
343+
let name = service.name().to_string();
342344
let runtime = Server::run_service(
343345
service,
344346
#[cfg(unix)]
@@ -347,7 +349,7 @@ impl Server {
347349
threads,
348350
conf.work_stealing,
349351
);
350-
runtimes.push(runtime);
352+
runtimes.push((runtime, name));
351353
}
352354

353355
// blocked on main loop so that it runs forever
@@ -379,20 +381,23 @@ impl Server {
379381
.unwrap_or(5),
380382
),
381383
};
382-
let shutdowns: Vec<_> = runtimes
384+
let shutdowns: Vec<(_, String)> = runtimes
383385
.into_iter()
384-
.map(|rt| {
386+
.map(|(rt, name)| {
385387
info!("Waiting for runtimes to exit!");
386-
thread::spawn(move || {
388+
let join = thread::spawn(move || {
387389
rt.shutdown_timeout(shutdown_timeout);
388390
thread::sleep(shutdown_timeout)
389-
})
391+
});
392+
(join, name)
390393
})
391394
.collect();
392-
for shutdown in shutdowns {
395+
for (shutdown, name) in shutdowns {
396+
info!("Waiting for service runtime {} to exit", name);
393397
if let Err(e) = shutdown.join() {
394-
error!("Failed to shutdown runtime: {:?}", e);
398+
error!("Failed to shutdown service runtime {}: {:?}", name, e);
395399
}
400+
debug!("Service runtime {} has exited", name);
396401
}
397402
info!("All runtimes exited, exiting now");
398403
std::process::exit(0)

0 commit comments

Comments
 (0)