]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Move pool dispose() before os.fork
authorGong Zhang <zhanggbj@cn.ibm.com>
Wed, 27 May 2015 09:10:17 +0000 (17:10 +0800)
committerGong Zhang <zhanggbj@cn.ibm.com>
Thu, 28 May 2015 03:13:23 +0000 (11:13 +0800)
Currently pool dispose() is done after os.fork, but this will
produce shared DB connections in child processes which may lead
to DB errors.

Move pool dispose() before os.fork. This will remove all existing
connections in the parent process and child processes will create
their own new ones.

Change-Id: Ie36417a64f0eb39b53dad61517f834aec37bacfb
Closes-Bug: 1458718

neutron/service.py
neutron/wsgi.py

index 4d8e9a8541312f9778f6e6e562d70a82b1b10995..708882b73124d8feedd97fa14198afd94ebcd3d8 100644 (file)
@@ -117,10 +117,6 @@ class RpcWorker(object):
         self._servers = []
 
     def start(self):
-        # We may have just forked from parent process.  A quick disposal of the
-        # existing sql connections avoids producing errors later when they are
-        # discovered to be broken.
-        session.dispose()
         self._servers = self._plugin.start_rpc_listeners()
 
     def wait(self):
@@ -157,6 +153,10 @@ def serve_rpc():
             rpc.start()
             return rpc
         else:
+            # dispose the whole pool before os.fork, otherwise there will
+            # be shared DB connections in child processes which may cause
+            # DB errors.
+            session.dispose()
             launcher = common_service.ProcessLauncher(wait_interval=1.0)
             launcher.launch_service(rpc, workers=cfg.CONF.rpc_workers)
             return launcher
index a31367ac6a6caa47204137899fd81d348a030701..bbd2d8fd898dc276e462c69da1395a93801e4ed4 100644 (file)
@@ -98,10 +98,6 @@ class WorkerService(object):
         self._server = None
 
     def start(self):
-        # We may have just forked from parent process.  A quick disposal of the
-        # existing sql connections avoids producing 500 errors later when they
-        # are discovered to be broken.
-        api.dispose()
         if CONF.use_ssl:
             self._service._socket = self._service.wrap_ssl(
                 self._service._socket)
@@ -234,6 +230,10 @@ class Server(object):
             service.start()
             systemd.notify_once()
         else:
+            # dispose the whole pool before os.fork, otherwise there will
+            # be shared DB connections in child processes which may cause
+            # DB errors.
+            api.dispose()
             # The API service runs in a number of child processes.
             # Minimize the cost of checking for child exit by extending the
             # wait interval past the default of 0.01s.