@@ -58,6 +58,11 @@ mod forward_auth;
58
58
mod proxy;
59
59
mod terminate;
60
60
61
+ /// How long to wait for the server to terminate gracefully before forcing it to shut down.
62
+ /// We want to keep this just high enough to serve short requests. Long-lived requests
63
+ /// will continue blocking indefinitely, which is why we need a timeout.
64
+ const TERMINATE_TIMEOUT_DURATION : std:: time:: Duration = std:: time:: Duration :: from_secs ( 2 ) ;
65
+
61
66
#[ derive( Serialize , Deserialize , Debug ) ]
62
67
pub struct StatusResponse {
63
68
pub status : String ,
@@ -295,6 +300,7 @@ impl ControllerServer {
295
300
self . heartbeat_handle . terminate ( ) . await ;
296
301
297
302
// Begin graceful shutdown of server.
303
+ tracing:: info!( "Initiating graceful shutdown of server" ) ;
298
304
let Some ( graceful_terminate_sender) = self . graceful_terminate_sender . take ( ) else {
299
305
return ;
300
306
} ;
@@ -307,16 +313,19 @@ impl ControllerServer {
307
313
return ;
308
314
} ;
309
315
310
- match server_handle. await {
311
- Ok ( Ok ( ( ) ) ) => {
316
+ match tokio :: time :: timeout ( TERMINATE_TIMEOUT_DURATION , server_handle) . await {
317
+ Ok ( Ok ( Ok ( ( ) ) ) ) => {
312
318
tracing:: info!( "Server gracefully terminated" ) ;
313
319
}
314
- Ok ( Err ( err) ) => {
320
+ Ok ( Ok ( Err ( err) ) ) => {
315
321
tracing:: error!( ?err, "Server error" ) ;
316
322
}
317
- Err ( err) => {
323
+ Ok ( Err ( err) ) => {
318
324
tracing:: error!( ?err, "Server error" ) ;
319
325
}
326
+ Err ( _) => {
327
+ tracing:: warn!( "Server did not terminate gracefully in time, forcing shutdown" ) ;
328
+ }
320
329
}
321
330
}
322
331
}
0 commit comments