Move state reporting initialization to after worker forking

We start state reporting thread before forking child processes. This
leads to possibility of fork in the middle of reporting process. This
can cause child processes to start with corrupted global state. In [0]
it represented itself as metadata agent not being able to make RPC call
because of lock acquired in main process before fork and released after
fork. See bug description for details.

[0] https://review.openstack.org/312393

Partial-Bug: 1594439

Change-Id: Id5079a296bc402c6f5b6cdb2df72811eab5bc6ed
This commit is contained in:
Yuriy Taraday 2016-06-20 16:39:03 +03:00
parent 5decf84c63
commit 7eeeb99a55
2 changed files with 6 additions and 9 deletions

View File

@ -232,7 +232,6 @@ class UnixDomainMetadataProxy(object):
self.conf = conf
agent_utils.ensure_directory_exists_without_file(
cfg.CONF.metadata_proxy_socket)
self._init_state_reporting()
def _init_state_reporting(self):
self.context = context.get_admin_context_without_session()
@ -297,4 +296,5 @@ class UnixDomainMetadataProxy(object):
workers=self.conf.metadata_workers,
backlog=self.conf.metadata_backlog,
mode=self._get_socket_mode())
self._init_state_reporting()
server.wait()

View File

@ -489,6 +489,9 @@ class TestUnixDomainMetadataProxy(base.BaseTestCase):
backlog=128, mode=0o644),
mock.call().wait()]
)
self.looping_mock.assert_called_once_with(p._report_state)
self.looping_mock.return_value.start.assert_called_once_with(
interval=mock.ANY)
def test_main(self):
with mock.patch.object(agent, 'UnixDomainMetadataProxy') as proxy:
@ -503,17 +506,11 @@ class TestUnixDomainMetadataProxy(base.BaseTestCase):
mock.call().run()]
)
def test_init_state_reporting(self):
with mock.patch('os.makedirs'):
proxy = agent.UnixDomainMetadataProxy(mock.Mock())
self.looping_mock.assert_called_once_with(proxy._report_state)
self.looping_mock.return_value.start.assert_called_once_with(
interval=mock.ANY)
def test_report_state(self):
with mock.patch('neutron.agent.rpc.PluginReportStateAPI') as state_api:
with mock.patch('os.makedirs'):
proxy = agent.UnixDomainMetadataProxy(mock.Mock())
proxy = agent.UnixDomainMetadataProxy(self.cfg.CONF)
proxy._init_state_reporting()
self.assertTrue(proxy.agent_state['start_flag'])
proxy._report_state()
self.assertNotIn('start_flag', proxy.agent_state)