Handle exception when worker unlocks already unlocked resource

The same exception is handled similary elsewhere.  This avoids a corner
case where the worker ends up throwing an exception here and blocking
the state machine from processing future messages.

Change-Id: I14709faac9228797f9ca043e45c550449437e561
Closes-bug: #1536901
This commit is contained in:
Adam Gandelman 2016-01-21 23:13:39 -08:00
parent 380fd931b2
commit 6cf7784f51
2 changed files with 27 additions and 1 deletions

View File

@ -333,6 +333,28 @@ class TestWorker(WorkerTestBase):
self._test__should_process_command(
fake_hash, cmds=cmds, key=DC_KEY, negative=True)
def test__release_resource_lock(self):
resource_id = '0ae77286-c0d6-11e5-9181-525400137dfc'
fake_lock = mock.Mock(release=mock.Mock())
self.w._resource_locks = {
resource_id: fake_lock
}
fake_sm = mock.Mock(resource_id=resource_id)
self.w._release_resource_lock(fake_sm)
self.assertTrue(fake_lock.release.called)
def test__release_resource_lock_unlocked(self):
resource_id = '0ae77286-c0d6-11e5-9181-525400137dfc'
fake_lock = mock.Mock(release=mock.Mock())
fake_lock.release.side_effect = threading.ThreadError()
self.w._resource_locks = {
resource_id: fake_lock
}
fake_sm = mock.Mock(resource_id=resource_id)
# just ensure we dont raise
self.w._release_resource_lock(fake_sm)
class TestResourceCache(WorkerTestBase):
def setUp(self):

View File

@ -678,7 +678,11 @@ class Worker(object):
LOG.debug('%s is already in the work queue', sm.resource_id)
def _release_resource_lock(self, sm):
self._resource_locks[sm.resource_id].release()
try:
self._resource_locks[sm.resource_id].release()
except threading.ThreadError:
# Already unlocked, that's OK.
pass
def report_status(self, show_config=True):
if show_config: