]> 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>
Mon, 8 Jun 2015 09:48:51 +0000 (17:48 +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.

(cherry-picked from 88e499d1c10eaae59546d9f16c9c9c262766de84)

Change-Id: Ie36417a64f0eb39b53dad61517f834aec37bacfb
Closes-Bug: 1458718

neutron/service.py
neutron/wsgi.py

index 448251c383a7ee3353f90c573958a89217305933..c529160ab5a17d509791854864a2207015304252 100644 (file)
@@ -116,10 +116,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.get_engine().pool.dispose()
         self._servers = self._plugin.start_rpc_listeners()
 
     def wait(self):
@@ -156,6 +152,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.get_engine().pool.dispose()
             launcher = common_service.ProcessLauncher(wait_interval=1.0)
             launcher.launch_service(rpc, workers=cfg.CONF.rpc_workers)
             return launcher
index cbb3292536d6f65063cefca5c2ce7959b1767e49..bd4b5e60fcd10adee372a60b6064064349f91bdb 100644 (file)
@@ -98,11 +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.
-        if CONF.database.connection:
-            api.get_engine().pool.dispose()
         self._server = self._service.pool.spawn(self._service._run,
                                                 self._application,
                                                 self._service._socket)
@@ -232,6 +227,11 @@ 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.
+            if CONF.database.connection:
+                api.get_engine().pool.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.