From 133a236565aa3a0ac39abe2ba46effd2cda1cceb Mon Sep 17 00:00:00 2001 From: Oliver Date: Sat, 30 May 2026 23:01:31 +1000 Subject: [PATCH] gunicorn configuration tweaks (#12048) - Ensure integer value - Close any DB connections post forking Co-authored-by: Matthias Mair --- contrib/container/gunicorn.conf.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/contrib/container/gunicorn.conf.py b/contrib/container/gunicorn.conf.py index 682f75b50d..9f95c0e53a 100644 --- a/contrib/container/gunicorn.conf.py +++ b/contrib/container/gunicorn.conf.py @@ -19,7 +19,7 @@ threads = 4 # Worker timeout (default = 90 seconds) -timeout = os.environ.get('INVENTREE_GUNICORN_TIMEOUT', '90') +timeout = int(os.environ.get('INVENTREE_GUNICORN_TIMEOUT', '90')) # Number of worker processes workers = os.environ.get('INVENTREE_GUNICORN_WORKERS', None) @@ -43,7 +43,13 @@ preload_app = True def post_fork(server, worker): - """Post-fork hook to set up logging for each worker.""" + """Post-fork hook called after each worker process is forked.""" + from django.db import connections + + # Close any DB connections inherited from the master process — PostgreSQL + # connections are not fork-safe, so each worker must open its own. + connections.close_all() + from django.conf import settings if not settings.TRACING_ENABLED: