Fix bug internal client's delete_object logs 499

Internal Client's doest not read body for 404.
So, When internal deleing object that not existed, proxy-server logs
its response code to 499.

In this patch, add a code that drain the reponse body to prevent
unexpected disconnect in proxy-server

Change-Id: I6d170fead798d0d539c69d27a6fa8a2d0123ca99
Closes-Bug: #1835324
This commit is contained in:
SeongSoo Cho
2019-11-06 15:32:56 +08:00
committed by Tim Burke
parent 23e1dba532
commit 7cb92810ac
2 changed files with 17 additions and 21 deletions

View File

@@ -618,7 +618,14 @@ class InternalClient(object):
"""
path = self.make_path(account, container, obj)
self.make_request('DELETE', path, (headers or {}), acceptable_statuses)
resp = self.make_request('DELETE', path, (headers or {}),
acceptable_statuses)
# Drain the response body to prevent unexpected disconnect
# in proxy-server
with closing_if_possible(resp.app_iter):
for iter_body in resp.app_iter:
pass
def get_object_metadata(
self, account, container, obj, metadata_prefix='',

View File

@@ -1163,28 +1163,17 @@ class TestInternalClient(unittest.TestCase):
self.assertEqual(1, client.set_metadata_called)
def test_delete_object(self):
class InternalClient(internal_client.InternalClient):
def __init__(self, test, path):
self.test = test
self.path = path
self.make_request_called = 0
def make_request(
self, method, path, headers, acceptable_statuses,
body_file=None):
self.make_request_called += 1
self.test.assertEqual('DELETE', method)
self.test.assertEqual(self.path, path)
self.test.assertEqual({}, headers)
self.test.assertEqual((2, 404), acceptable_statuses)
self.test.assertIsNone(body_file)
account, container, obj = path_parts()
path = make_path(account, container, obj)
client = InternalClient(self, path)
path = make_path_info(account, container, obj)
client, app = get_client_app()
app.register('DELETE', path, swob.HTTPNoContent, {})
client.delete_object(account, container, obj)
self.assertEqual(1, client.make_request_called)
self.assertEqual(app.unclosed_requests, {})
self.assertEqual(1, len(app._calls))
app.register('DELETE', path, swob.HTTPNotFound, {})
client.delete_object(account, container, obj)
self.assertEqual(app.unclosed_requests, {})
self.assertEqual(2, len(app._calls))
def test_get_object_metadata(self):
account, container, obj = path_parts()