From 803618da03e8ed6bb65449d5f8517fab94a3fd4e Mon Sep 17 00:00:00 2001 From: Stan Triepels <1939656+GDay@users.noreply.github.com> Date: Fri, 14 Oct 2022 02:08:48 +0200 Subject: [PATCH] Fix connection issues with CONN_MAX_AGE > 0 (#9) Co-authored-by: Marc Sabatier --- django_q/cluster.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/django_q/cluster.py b/django_q/cluster.py index a1b76d2..7f2bbbf 100644 --- a/django_q/cluster.py +++ b/django_q/cluster.py @@ -213,8 +213,9 @@ class Sentinel: :param process: the process to reincarnate :type process: Process or None """ + # close connections before spawning new process if not Conf.SYNC: - db.connections.close_all() # Close any old connections + db.connections.close_all() if process == self.monitor: self.monitor = self.spawn_monitor() logger.error(_(f"reincarnated monitor {process.name} after sudden death")) @@ -238,8 +239,9 @@ class Sentinel: def spawn_cluster(self): self.pool = [] Stat(self).save() + # close connections before spawning new process if not Conf.SYNC: - db.connection.close() + db.connections.close_all() # spawn worker pool for __ in range(self.pool_size): self.spawn_worker() @@ -695,7 +697,7 @@ def close_old_django_connections(): logger.warning( "Preserving django database connections because sync=True. Beware " "that tasks are now injected in the calling context/transactions " - "which may result in unexpected bahaviour." + "which may result in unexpected behaviour." ) else: db.close_old_connections()