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:
parent
c36eeb3502
commit
34c2a45d8d
@ -65,7 +65,10 @@ class Receiver(object):
|
|||||||
self.device = None
|
self.device = None
|
||||||
self.partition = None
|
self.partition = None
|
||||||
self.fp = 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):
|
def __call__(self):
|
||||||
"""
|
"""
|
||||||
@ -100,6 +103,9 @@ class Receiver(object):
|
|||||||
yield data
|
yield data
|
||||||
for data in self.updates():
|
for data in self.updates():
|
||||||
yield data
|
yield data
|
||||||
|
# We didn't raise an exception, so end the request
|
||||||
|
# normally.
|
||||||
|
self.disconnect = False
|
||||||
finally:
|
finally:
|
||||||
if self.app.replication_semaphore:
|
if self.app.replication_semaphore:
|
||||||
self.app.replication_semaphore.release()
|
self.app.replication_semaphore.release()
|
||||||
@ -288,10 +294,6 @@ class Receiver(object):
|
|||||||
raise Exception('Looking for :UPDATES: START got %r' % line[:1024])
|
raise Exception('Looking for :UPDATES: START got %r' % line[:1024])
|
||||||
successes = 0
|
successes = 0
|
||||||
failures = 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:
|
while True:
|
||||||
with exceptions.MessageTimeout(
|
with exceptions.MessageTimeout(
|
||||||
self.app.client_timeout, 'updates line'):
|
self.app.client_timeout, 'updates line'):
|
||||||
@ -376,8 +378,6 @@ class Receiver(object):
|
|||||||
raise swob.HTTPInternalServerError(
|
raise swob.HTTPInternalServerError(
|
||||||
'ERROR: With :UPDATES: %d failures to %d successes' %
|
'ERROR: With :UPDATES: %d failures to %d successes' %
|
||||||
(failures, successes))
|
(failures, successes))
|
||||||
# We didn't raise an exception, so end the request normally.
|
|
||||||
self.disconnect = False
|
|
||||||
yield ':UPDATES: START\r\n'
|
yield ':UPDATES: START\r\n'
|
||||||
yield ':UPDATES: END\r\n'
|
yield ':UPDATES: END\r\n'
|
||||||
for data in self._ensure_flush():
|
for data in self._ensure_flush():
|
||||||
|
@ -364,7 +364,7 @@ class TestReceiver(unittest.TestCase):
|
|||||||
self.body_lines(resp.body),
|
self.body_lines(resp.body),
|
||||||
[":ERROR: 408 '0.01 seconds: missing_check line'"])
|
[":ERROR: 408 '0.01 seconds: missing_check line'"])
|
||||||
self.assertEqual(resp.status_int, 200)
|
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(
|
self.controller.logger.error.assert_called_once_with(
|
||||||
'2.3.4.5/sda1/1 TIMEOUT in replication.Receiver: '
|
'2.3.4.5/sda1/1 TIMEOUT in replication.Receiver: '
|
||||||
'0.01 seconds: missing_check line')
|
'0.01 seconds: missing_check line')
|
||||||
@ -406,7 +406,7 @@ class TestReceiver(unittest.TestCase):
|
|||||||
self.body_lines(resp.body),
|
self.body_lines(resp.body),
|
||||||
[":ERROR: 0 'test exception'"])
|
[":ERROR: 0 'test exception'"])
|
||||||
self.assertEqual(resp.status_int, 200)
|
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(
|
self.controller.logger.exception.assert_called_once_with(
|
||||||
'3.4.5.6/sda1/1 EXCEPTION in replication.Receiver')
|
'3.4.5.6/sda1/1 EXCEPTION in replication.Receiver')
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user