From: Gong Zhang Date: Wed, 27 May 2015 09:10:17 +0000 (+0800) Subject: Move pool dispose() before os.fork X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=2884595c96f331facb11510057d68d5a01bb4747;p=openstack-build%2Fneutron-build.git Move pool dispose() before os.fork 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 --- diff --git a/neutron/service.py b/neutron/service.py index 448251c38..c529160ab 100644 --- a/neutron/service.py +++ b/neutron/service.py @@ -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 diff --git a/neutron/wsgi.py b/neutron/wsgi.py index cbb329253..bd4b5e60f 100644 --- a/neutron/wsgi.py +++ b/neutron/wsgi.py @@ -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.