This commit is contained in:
+11
-1
@@ -587,7 +587,17 @@ class NFOGuardDatabase:
|
|||||||
"""Close all database connections"""
|
"""Close all database connections"""
|
||||||
if hasattr(self._local, 'connection'):
|
if hasattr(self._local, 'connection'):
|
||||||
try:
|
try:
|
||||||
|
# For PostgreSQL, ensure all transactions are committed/rolled back
|
||||||
|
try:
|
||||||
|
# Force rollback any open transactions
|
||||||
|
self._local.connection.rollback()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Close the connection
|
||||||
self._local.connection.close()
|
self._local.connection.close()
|
||||||
delattr(self._local, 'connection')
|
delattr(self._local, 'connection')
|
||||||
except Exception:
|
print("✅ Database connection closed successfully")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"⚠️ Error closing database connection: {e}")
|
||||||
pass # Connection may already be closed
|
pass # Connection may already be closed
|
||||||
@@ -146,6 +146,18 @@ def signal_handler(signum, frame):
|
|||||||
_log("WARNING", f"Error closing database: {e}")
|
_log("WARNING", f"Error closing database: {e}")
|
||||||
|
|
||||||
_log("INFO", "Graceful shutdown complete")
|
_log("INFO", "Graceful shutdown complete")
|
||||||
|
|
||||||
|
# Force exit after 2 seconds if graceful shutdown doesn't work
|
||||||
|
import threading
|
||||||
|
def force_exit():
|
||||||
|
import time
|
||||||
|
time.sleep(2)
|
||||||
|
_log("WARNING", "Force exiting after timeout")
|
||||||
|
os._exit(0)
|
||||||
|
|
||||||
|
force_thread = threading.Thread(target=force_exit, daemon=True)
|
||||||
|
force_thread.start()
|
||||||
|
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user