chore(docker): close neomodel driver on gunicorn worker exit
All checks were successful
CVE Scan & Docker Build / security-scan (push) Successful in 3m9s
CVE Scan & Docker Build / build-and-push (push) Successful in 2m38s

This commit is contained in:
2026-05-23 19:51:25 -04:00
parent 93639188d3
commit 7d95133c74

View File

@@ -34,3 +34,19 @@ def post_worker_init(worker):
logging.getLogger("library.apps").warning(
"Startup probe crashed: %s", exc, exc_info=True
)
def worker_exit(server, worker):
# Neomodel lazily creates a neo4j.Driver on first cypher_query and
# holds it for the process lifetime. Newer neo4j drivers warn (and
# will eventually fail to clean up) if the driver is destroyed
# without an explicit close. Close it here so each gunicorn worker
# shuts down cleanly.
try:
from neomodel import db
db.close_connection()
except Exception as exc:
logging.getLogger("neomodel").warning(
"Failed to close neomodel driver on worker exit: %s", exc
)