@@ -49,6 +49,7 @@ class AccessMode(str, Enum):
49
49
# Global variables
50
50
db_connection = DbConnPool ()
51
51
current_access_mode = AccessMode .UNRESTRICTED
52
+ shutdown_in_progress = False
52
53
53
54
54
55
async def get_sql_driver () -> Union [SqlDriver , SafeSqlDriver ]:
@@ -545,32 +546,25 @@ async def main():
545
546
logger .warning ("Signal handling not supported on Windows" )
546
547
pass
547
548
548
- # Run the app with FastMCP's stdio method
549
- try :
550
- await mcp .run_stdio_async ()
551
- finally :
552
- # Close the connection pool when exiting
553
- await shutdown ()
549
+ await mcp .run_stdio_async ()
554
550
555
551
556
552
async def shutdown (sig = None ):
557
553
"""Clean shutdown of the server."""
558
- if sig :
559
- logger .info (f"Received exit signal { sig .name } " )
554
+ global shutdown_in_progress
560
555
561
- logger .info ("Closing database connections..." )
562
- await db_connection .close ()
556
+ import os
557
+ if shutdown_in_progress :
558
+ logger .warning ("Forcing immediate exit" )
563
559
564
- # Give tasks a chance to complete
565
- try :
566
- tasks = [t for t in asyncio .all_tasks () if t is not asyncio .current_task ()]
567
- if tasks :
568
- logger .info (f"Waiting for { len (tasks )} tasks to complete..." )
569
- await asyncio .gather (* tasks , return_exceptions = True )
570
- except Exception as e :
571
- logger .warning (f"Error during shutdown: { e } " )
560
+ os ._exit (1 ) # Use immediate process termination instead of sys.exit
561
+
562
+ shutdown_in_progress = True
563
+
564
+ if sig :
565
+ logger .info (f"Received exit signal { sig .name } " )
572
566
573
- logger . info ( "Shutdown complete." )
567
+ os . _exit ( 0 )
574
568
575
569
576
570
if __name__ == "__main__" :
0 commit comments