From 34c2a45d8d16ac8128451d05e2b2d5815b15e461 Mon Sep 17 00:00:00 2001 From: gholt Date: Fri, 6 Dec 2013 04:12:15 +0000 Subject: [PATCH] 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 --- swift/obj/ssync_receiver.py | 14 +++++++------- test/unit/obj/test_ssync_receiver.py | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/swift/obj/ssync_receiver.py b/swift/obj/ssync_receiver.py index bf2e1726d0..203c3bd91b 100644 --- a/swift/obj/ssync_receiver.py +++ b/swift/obj/ssync_receiver.py @@ -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(): diff --git a/test/unit/obj/test_ssync_receiver.py b/test/unit/obj/test_ssync_receiver.py index babc2ce936..2c80914fe9 100644 --- a/test/unit/obj/test_ssync_receiver.py +++ b/test/unit/obj/test_ssync_receiver.py @@ -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')