Fix connection issues with CONN_MAX_AGE > 0 (#9)

Co-authored-by: Marc Sabatier <marc@sabatier.online>
This commit is contained in:
Stan Triepels
2022-10-14 02:08:48 +02:00
committed by GitHub
parent 1edb426541
commit 803618da03

View File

@@ -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()