From 313d03b75bf845855247235ca8e42314c6c58833 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Wed, 31 Oct 2018 12:46:58 -0400 Subject: [PATCH] cherrypick --- endpoints/verbs/__init__.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/endpoints/verbs/__init__.py b/endpoints/verbs/__init__.py index bf3823fe9..e6c677810 100644 --- a/endpoints/verbs/__init__.py +++ b/endpoints/verbs/__init__.py @@ -112,7 +112,15 @@ def _write_derived_image_to_storage(verb, derived_image, queue_file): # Re-Initialize the storage engine because some may not respond well to forking (e.g. S3) store = Storage(app, metric_queue, config_provider=config_provider, ip_resolver=ip_resolver) image_path = model.get_blob_path(derived_image.blob) - store.stream_write(derived_image.blob.locations, image_path, queue_file) + + try: + store.stream_write(derived_image.blob.locations, image_path, queue_file) + except IOError as ex: + logger.debug('Exception when writing %s derived image %s: %s', verb, derived_image, ex) + + with database.UseThenDisconnect(app.config): + model.delete_derived_image(derived_image) + queue_file.close()