@@ -189,69 +189,65 @@ fn main() {
189189
190190 // Set up graceful shutdown handling
191191 let shutdown_signal = async {
192- let signal_result = async {
193- #[ cfg( unix) ]
194- {
195- // Set up SIGTERM handler with proper error handling
196- // Note: We only handle SIGTERM explicitly; ctrl_c() handles SIGINT automatically
197- match signal:: unix:: signal ( signal:: unix:: SignalKind :: terminate ( ) ) {
198- Ok ( mut sigterm) => {
199- tokio:: select! {
200- _ = sigterm. recv( ) => {
201- info!( "=== EV-RETH: Received SIGTERM, initiating graceful shutdown ===" ) ;
202- Ok ( ( ) )
203- }
204- result = signal:: ctrl_c( ) => {
205- match result {
206- Ok ( _) => {
207- info!( "=== EV-RETH: Received SIGINT/Ctrl+C, initiating graceful shutdown ===" ) ;
208- Ok ( ( ) )
209- }
210- Err ( err) => {
211- tracing:: error!( "Failed to wait for Ctrl+C: {}" , err) ;
212- Err ( err)
213- }
192+ #[ cfg( unix) ]
193+ {
194+ // On Unix systems, handle both SIGTERM and SIGINT (Ctrl+C) separately for clarity
195+ // SIGTERM is typically sent by process managers for graceful shutdown
196+ // SIGINT is sent by Ctrl+C from terminal
197+ match signal:: unix:: signal ( signal:: unix:: SignalKind :: terminate ( ) ) {
198+ Ok ( mut sigterm) => {
199+ // Successfully set up SIGTERM handler, now wait for either SIGTERM or SIGINT
200+ tokio:: select! {
201+ _ = sigterm. recv( ) => {
202+ info!( "=== EV-RETH: Received SIGTERM, initiating graceful shutdown ===" ) ;
203+ }
204+ result = signal:: ctrl_c( ) => {
205+ match result {
206+ Ok ( _) => {
207+ info!( "=== EV-RETH: Received SIGINT/Ctrl+C, initiating graceful shutdown ===" ) ;
208+ }
209+ Err ( err) => {
210+ tracing:: error!( "Failed to wait for SIGINT: {}" , err) ;
211+ // Continue with shutdown even if SIGINT handling failed
214212 }
215213 }
216214 }
217215 }
218- Err ( err) => {
219- tracing:: warn!( "Failed to install SIGTERM handler: {}, falling back to SIGINT only" , err) ;
220- // Fall back to just handling SIGINT/Ctrl+C
221- match signal:: ctrl_c ( ) . await {
222- Ok ( _) => {
223- info ! ( "=== EV-RETH: Received SIGINT/Ctrl+C, initiating graceful shutdown ===" ) ;
224- Ok ( ( ) )
225- }
226- Err ( ctrl_c_err) => {
227- tracing:: error!( "Failed to wait for Ctrl+C: {}" , ctrl_c_err) ;
228- Err ( ctrl_c_err)
229- }
216+ }
217+ Err ( err) => {
218+ tracing:: warn!( "Failed to install SIGTERM handler: {}, falling back to SIGINT only" , err) ;
219+ // Fall back to just handling SIGINT/Ctrl+C
220+ match signal:: ctrl_c ( ) . await {
221+ Ok ( _) => {
222+ info ! ( "=== EV-RETH: Received SIGINT/Ctrl+C, initiating graceful shutdown ===" ) ;
223+ }
224+ Err ( ctrl_c_err) => {
225+ tracing:: error!( "Failed to wait for SIGINT: {}" , ctrl_c_err) ;
226+ // If we can't handle any signals, we should still shut down gracefully
227+ // This prevents the application from hanging indefinitely
228+ tracing:: warn!( "No signal handling available, shutdown will only occur on natural node exit" ) ;
229+ // Wait indefinitely - this branch should rarely be reached
230+ std:: future:: pending :: < ( ) > ( ) . await ;
230231 }
231232 }
232233 }
233234 }
235+ }
234236
235- #[ cfg( not( unix) ) ]
236- {
237- // On non-Unix systems, only handle Ctrl+C
238- match signal:: ctrl_c ( ) . await {
239- Ok ( _) => {
240- info ! ( "=== EV-RETH: Received SIGINT/Ctrl+C, initiating graceful shutdown ===" ) ;
241- Ok ( ( ) )
242- }
243- Err ( err ) => {
244- tracing:: error !( "Failed to wait for Ctrl+C: {}" , err ) ;
245- Err ( err )
246- }
237+ #[ cfg( not( unix) ) ]
238+ {
239+ // On non-Unix systems, only handle Ctrl+C (SIGINT)
240+ match signal:: ctrl_c ( ) . await {
241+ Ok ( _) => {
242+ info ! ( "=== EV-RETH: Received SIGINT/Ctrl+C, initiating graceful shutdown ===" ) ;
243+ }
244+ Err ( err ) => {
245+ tracing :: error! ( "Failed to wait for SIGINT: {}" , err ) ;
246+ tracing:: warn !( "No signal handling available, shutdown will only occur on natural node exit" ) ;
247+ // Wait indefinitely - this branch should rarely be reached
248+ std :: future :: pending :: < ( ) > ( ) . await ;
247249 }
248250 }
249- } . await ;
250-
251- // Handle signal errors gracefully - if we can't set up signal handling,
252- // we should still allow the application to continue running
253- if let Err ( err) = signal_result {
254- tracing:: warn!( "Signal handling failed: {}, application will continue without graceful shutdown" , err) ;
255251 }
256252 } ;
257253
0 commit comments