Skip to content

Commit

Permalink
Handle client disconnect during image upload
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Paul Bourke committed Jul 18, 2013
1 parent 85cbff0 commit 3904860
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions glance/api/v1/upload_utils.py
Expand Up @@ -177,6 +177,14 @@ def _kill_mismatched(image_meta, attr, actual):
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)
Expand Down
10 changes: 10 additions & 0 deletions glance/tests/unit/v1/test_upload_utils.py
Expand Up @@ -287,6 +287,16 @@ def test_upload_data_to_store_http_error(self):
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,
Expand Down

0 comments on commit 3904860

Please sign in to comment.