Merge "Prevent traceback in object-server on client disconnect"

This commit is contained in:
Jenkins 2017-02-21 21:02:51 +00:00 committed by Gerrit Code Review
commit 413fb2b84f
2 changed files with 23 additions and 1 deletions

View File

@ -407,7 +407,10 @@ class ObjectController(BaseStorageServer):
def _make_timeout_reader(self, file_like):
def timeout_reader():
with ChunkReadTimeout(self.client_timeout):
return file_like.read(self.network_chunk_size)
try:
return file_like.read(self.network_chunk_size)
except (IOError, ValueError):
raise ChunkReadError
return timeout_reader
def _read_put_commit_message(self, mime_documents_iter):

View File

@ -1926,6 +1926,25 @@ class TestObjectController(unittest.TestCase):
resp = req.get_response(self.object_controller)
self.assertEqual(resp.status_int, 408)
def test_PUT_client_closed_connection(self):
class fake_input(object):
def read(self, *a, **kw):
# On client disconnect during a chunked transfer, eventlet
# may raise a ValueError (or ChunkReadError, following
# https://github.com/eventlet/eventlet/commit/c3ce3ee -- but
# that inherits from ValueError)
raise ValueError
timestamp = normalize_timestamp(time())
req = Request.blank(
'/sda1/p/a/c/o', environ={'REQUEST_METHOD': 'PUT'},
headers={'X-Timestamp': timestamp,
'Content-Type': 'text/plain',
'Content-Length': '6'})
req.environ['wsgi.input'] = fake_input()
resp = req.get_response(self.object_controller)
self.assertEqual(resp.status_int, 499)
def test_PUT_system_metadata(self):
# check that sysmeta is stored in diskfile
timestamp = normalize_timestamp(time())