From 3904860467d87c74c046974963070e029a89ba5e Mon Sep 17 00:00:00 2001 From: Paul Bourke Date: Thu, 27 Jun 2013 11:38:00 +0000 Subject: [PATCH] Handle client disconnect during image upload If a user does a ^C during a chunked image upload, eventlet.wsgi.server will raise one of ValueError or IOError when trying to read the next chunk. Handle this common scenario by raising(logging) a HTTPBadRequest error rather than HTTPInternalServerError. Fixes bug 1196953 Change-Id: Ic88b142a40c548141be4b40a15f94b71603814e9 --- glance/api/v1/upload_utils.py | 8 ++++++++ glance/tests/unit/v1/test_upload_utils.py | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/glance/api/v1/upload_utils.py b/glance/api/v1/upload_utils.py index 793d5acd3a..189d062ab3 100644 --- a/glance/api/v1/upload_utils.py +++ b/glance/api/v1/upload_utils.py @@ -177,6 +177,14 @@ def upload_data_to_store(req, image_meta, image_data, store, notifier): LOG.exception(msg) safe_kill(req, image_id) + except (ValueError, IOError) as e: + msg = _("Client disconnected before sending all data to backend") + LOG.debug(msg) + safe_kill(req, image_id) + raise webob.exc.HTTPBadRequest(explanation=msg, + content_type="text/plain", + request=req) + except Exception as e: msg = _("Failed to upload image %s" % image_id) LOG.exception(msg) diff --git a/glance/tests/unit/v1/test_upload_utils.py b/glance/tests/unit/v1/test_upload_utils.py index d6763ad772..bfd4e89ee2 100644 --- a/glance/tests/unit/v1/test_upload_utils.py +++ b/glance/tests/unit/v1/test_upload_utils.py @@ -287,6 +287,16 @@ class TestUploadUtils(base.StoreClearingUnitTest): webob.exc.HTTPError, webob.exc.HTTPError) + def test_upload_data_to_store_client_disconnect(self): + self._test_upload_data_to_store_exception( + ValueError, + webob.exc.HTTPBadRequest) + + def test_upload_data_to_store_client_disconnect_ioerror(self): + self._test_upload_data_to_store_exception( + IOError, + webob.exc.HTTPBadRequest) + def test_upload_data_to_store_exception(self): self._test_upload_data_to_store_exception( Exception,