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
(cherry picked from commit 7eeeb99a55
)
This commit is contained in:
parent
c9529c8912
commit
ae6a2ec2a5
|
@ -236,7 +236,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()
|
||||
|
@ -301,4 +300,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()
|
||||
|
|
|
@ -475,6 +475,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:
|
||||
|
@ -489,17 +492,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)
|
||||
|
|
Loading…
Reference in New Issue