浏览代码

Initialize DB connection for the worker processes and close them when the process ends (#3317)

Internal Jira: CDPD-56487

This was tested manually in an internal cluster which exhibited the below exception when is_alive calls where initiated and while restarting/stopping the processes.

django.db.utils.OperationalError: ORA-03135: connection lost contact
django.db.utils.OperationalError: ORA-03113: end-of-file on communication channel
django.db.utils.OperationalError: ORA-03114: Not Connected to Oracle
Mahesh Balakrishnan 2 年之前
父节点
当前提交
c0dc0b90f5
共有 1 个文件被更改,包括 10 次插入1 次删除
  1. 10 1
      desktop/core/src/desktop/management/commands/rungunicornserver.py

+ 10 - 1
desktop/core/src/desktop/management/commands/rungunicornserver.py

@@ -33,6 +33,7 @@ from desktop.lib.paths import get_desktop_root
 from django.core.management.base import BaseCommand
 from django.core.wsgi import get_wsgi_application
 from django.utils.translation import gettext as _
+from django.db import connection
 from gunicorn import util
 from six import iteritems
 
@@ -76,6 +77,12 @@ def post_fork(server, worker):
   with open(PID_FILE, "a") as f:
     f.write("%s\n"%worker.pid)
 
+def post_worker_init(worker):
+  connection.connect()
+
+def worker_int(worker):
+  connection.close()
+
 def enable_logging(args, options):
   HUE_DESKTOP_VERSION = pkg_resources.get_distribution("desktop").version or "Unknown"
   # Start basic logging as soon as possible.
@@ -207,7 +214,9 @@ def rungunicornserver(args=[], options={}):
       'worker_connections': 1000,
       'worker_tmp_dir': options['worker_tmp_dir'],
       'workers': conf.GUNICORN_NUMBER_OF_WORKERS.get() if conf.GUNICORN_NUMBER_OF_WORKERS.get() is not None else 5,
-      'post_fork': post_fork
+      'post_fork': post_fork,
+      'post_worker_init': post_worker_init,
+      'worker_int': worker_int
   }
   StandaloneApplication(handler_app, gunicorn_options).run()