@@ -314,6 +314,10 @@ pub async fn run_servers<S, B>(
314314 B :: Data : Send ,
315315 B :: Error : std:: error:: Error + Send + Sync + ' static ,
316316{
317+ // This guard on the shutdown token is to ensure that if this task crashes for
318+ // any reason, the server will shut down
319+ let _guard = soft_shutdown_token. clone ( ) . drop_guard ( ) ;
320+
317321 // Create a stream of accepted connections out of the listeners
318322 let mut accept_stream: SelectAll < _ > = listeners
319323 . into_iter ( )
@@ -360,7 +364,7 @@ pub async fn run_servers<S, B>(
360364 connection_tasks. spawn( conn) ;
361365 } ,
362366 Some ( Ok ( Err ( _e) ) ) => { /* Connection did not finish handshake, error should be logged in `accept` */ } ,
363- Some ( Err ( e) ) => tracing:: error!( "Join error: {e} ") ,
367+ Some ( Err ( e) ) => tracing:: error!( error = & e as & dyn std :: error:: Error , "Join error ") ,
364368 None => tracing:: error!( "Join set was polled even though it was empty" ) ,
365369 }
366370 } ,
@@ -369,8 +373,8 @@ pub async fn run_servers<S, B>(
369373 res = connection_tasks. join_next( ) , if !connection_tasks. is_empty( ) => {
370374 match res {
371375 Some ( Ok ( Ok ( ( ) ) ) ) => tracing:: trace!( "Connection finished" ) ,
372- Some ( Ok ( Err ( e) ) ) => tracing:: error!( "Error while serving connection: {e} " ) ,
373- Some ( Err ( e) ) => tracing:: error!( "Join error: {e} ") ,
376+ Some ( Ok ( Err ( e) ) ) => tracing:: error!( error = & * e as & dyn std :: error :: Error , "Error while serving connection" ) ,
377+ Some ( Err ( e) ) => tracing:: error!( error = & e as & dyn std :: error:: Error , "Join error ") ,
374378 None => tracing:: error!( "Join set was polled even though it was empty" ) ,
375379 }
376380 } ,
@@ -412,7 +416,7 @@ pub async fn run_servers<S, B>(
412416 connection_tasks. spawn( conn) ;
413417 }
414418 Some ( Ok ( Err ( _e) ) ) => { /* Connection did not finish handshake, error should be logged in `accept` */ } ,
415- Some ( Err ( e) ) => tracing:: error!( "Join error: {e} ") ,
419+ Some ( Err ( e) ) => tracing:: error!( error = & e as & dyn std :: error:: Error , "Join error ") ,
416420 None => tracing:: error!( "Join set was polled even though it was empty" ) ,
417421 }
418422 } ,
@@ -421,8 +425,8 @@ pub async fn run_servers<S, B>(
421425 res = connection_tasks. join_next( ) , if !connection_tasks. is_empty( ) => {
422426 match res {
423427 Some ( Ok ( Ok ( ( ) ) ) ) => tracing:: trace!( "Connection finished" ) ,
424- Some ( Ok ( Err ( e) ) ) => tracing:: error!( "Error while serving connection: {e} " ) ,
425- Some ( Err ( e) ) => tracing:: error!( "Join error: {e} ") ,
428+ Some ( Ok ( Err ( e) ) ) => tracing:: error!( error = & * e as & dyn std :: error :: Error , "Error while serving connection" ) ,
429+ Some ( Err ( e) ) => tracing:: error!( error = & e as & dyn std :: error:: Error , "Join error ") ,
426430 None => tracing:: error!( "Join set was polled even though it was empty" ) ,
427431 }
428432 } ,
0 commit comments