From 87adfe58891bf35fe67014256bf2741aa7a6bfbc Mon Sep 17 00:00:00 2001 From: Ryan Petrello Date: Wed, 15 Aug 2018 14:18:52 -0400 Subject: [PATCH] close DB and cache sockets _immediately_ before we fork callback workers --- .../management/commands/run_callback_receiver.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/awx/main/management/commands/run_callback_receiver.py b/awx/main/management/commands/run_callback_receiver.py index 14e44496bb..ee45d0ada2 100644 --- a/awx/main/management/commands/run_callback_receiver.py +++ b/awx/main/management/commands/run_callback_receiver.py @@ -64,15 +64,22 @@ class CallbackBrokerWorker(ConsumerMixin): return _handler if use_workers: - django_connection.close() - django_cache.close() for idx in range(settings.JOB_EVENT_WORKERS): queue_actual = MPQueue(settings.JOB_EVENT_MAX_QUEUE_SIZE) w = Process(target=self.callback_worker, args=(queue_actual, idx,)) - w.start() if settings.DEBUG: - logger.info('Started worker %s' % str(idx)) + logger.info('Starting worker %s' % str(idx)) self.worker_queues.append([0, queue_actual, w]) + + # It's important to close these _right before_ we fork; we + # don't want the forked processes to inherit the open sockets + # for the DB and memcached connections (that way lies race + # conditions) + django_connection.close() + django_cache.close() + for _, _, w in self.worker_queues: + w.start() + elif settings.DEBUG: logger.warn('Started callback receiver (no workers)')