Make ssync_receiver drop conn on exc

Before, the ssync receiver wouldn't hang up the connection with all
errors. Now it will. Hanging up early will ensure the remote end gets
a "broken pipe" type error right away instead of it possible sending
more data for quite some time before finally reading the error.

Change-Id: I2d3d55baaf10f99e7edce7843a7106875752020a
This commit is contained in:
gholt 2013-12-06 04:12:15 +00:00
parent c36eeb3502
commit 34c2a45d8d
2 changed files with 9 additions and 9 deletions

View File

@ -65,7 +65,10 @@ class Receiver(object):
self.device = None
self.partition = None
self.fp = None
self.disconnect = False
# We default to dropping the connection in case there is any exception
# raised during processing because otherwise the sender could send for
# quite some time before realizing it was all in vain.
self.disconnect = True
def __call__(self):
"""
@ -100,6 +103,9 @@ class Receiver(object):
yield data
for data in self.updates():
yield data
# We didn't raise an exception, so end the request
# normally.
self.disconnect = False
finally:
if self.app.replication_semaphore:
self.app.replication_semaphore.release()
@ -288,10 +294,6 @@ class Receiver(object):
raise Exception('Looking for :UPDATES: START got %r' % line[:1024])
successes = 0
failures = 0
# We default to dropping the connection in case there is any exception
# raised during processing because otherwise the sender could send for
# quite some time before realizing it was all in vain.
self.disconnect = True
while True:
with exceptions.MessageTimeout(
self.app.client_timeout, 'updates line'):
@ -376,8 +378,6 @@ class Receiver(object):
raise swob.HTTPInternalServerError(
'ERROR: With :UPDATES: %d failures to %d successes' %
(failures, successes))
# We didn't raise an exception, so end the request normally.
self.disconnect = False
yield ':UPDATES: START\r\n'
yield ':UPDATES: END\r\n'
for data in self._ensure_flush():

View File

@ -364,7 +364,7 @@ class TestReceiver(unittest.TestCase):
self.body_lines(resp.body),
[":ERROR: 408 '0.01 seconds: missing_check line'"])
self.assertEqual(resp.status_int, 200)
self.assertFalse(mock_shutdown_safe.called)
self.assertTrue(mock_shutdown_safe.called)
self.controller.logger.error.assert_called_once_with(
'2.3.4.5/sda1/1 TIMEOUT in replication.Receiver: '
'0.01 seconds: missing_check line')
@ -406,7 +406,7 @@ class TestReceiver(unittest.TestCase):
self.body_lines(resp.body),
[":ERROR: 0 'test exception'"])
self.assertEqual(resp.status_int, 200)
self.assertFalse(mock_shutdown_safe.called)
self.assertTrue(mock_shutdown_safe.called)
self.controller.logger.exception.assert_called_once_with(
'3.4.5.6/sda1/1 EXCEPTION in replication.Receiver')