From 7fd5a128722a4c42406d195b46edb0b0fbc3c3e1 Mon Sep 17 00:00:00 2001 From: Tim Burke Date: Thu, 24 May 2018 15:44:39 -0700 Subject: [PATCH] Stop holding on to sys.exc_info tuples quite so much This used to be necessary on older eventlet, or you'd get TypeErrors when you went to reraise. Following eventlet 0.13.0, however, it's just extra code. For the original eventlet issue, see https://web.archive.org/web/20140823005223/https://bitbucket.org/eventlet/eventlet/issue/149/yield-in-except-clause-with-wilcard-raise Change-Id: I19ad0968a82827bdd4ef75fde9ed51f193627d6e Related-Bug: 1181146 --- swift/common/internal_client.py | 2 +- swift/common/middleware/proxy_logging.py | 5 +---- swift/common/middleware/s3api/acl_handlers.py | 5 +---- .../middleware/s3api/controllers/bucket.py | 4 +--- .../s3api/controllers/multi_delete.py | 5 +---- .../s3api/controllers/multi_upload.py | 4 +--- .../middleware/s3api/controllers/obj.py | 5 +---- swift/common/middleware/s3api/etree.py | 4 +--- swift/proxy/controllers/base.py | 22 +++++++++---------- 9 files changed, 18 insertions(+), 38 deletions(-) diff --git a/swift/common/internal_client.py b/swift/common/internal_client.py index 25c78f922f..3d777b073f 100644 --- a/swift/common/internal_client.py +++ b/swift/common/internal_client.py @@ -221,7 +221,7 @@ class InternalClient(object): raise UnexpectedResponse(msg, resp) if exc_type: # To make pep8 tool happy, in place of raise t, v, tb: - six.reraise(exc_type(*exc_value.args), None, exc_traceback) + six.reraise(exc_type, exc_value, exc_traceback) def _get_metadata( self, path, metadata_prefix='', acceptable_statuses=(2,), diff --git a/swift/common/middleware/proxy_logging.py b/swift/common/middleware/proxy_logging.py index f3c236a6c9..cf001f067a 100644 --- a/swift/common/middleware/proxy_logging.py +++ b/swift/common/middleware/proxy_logging.py @@ -71,10 +71,8 @@ if this is a middleware subrequest or not. A log processor calculating bandwidth usage will want to only sum up logs with no swift.source. """ -import sys import time -import six from six.moves.urllib.parse import quote from swift.common.swob import Request from swift.common.utils import (get_logger, get_remote_client, @@ -333,13 +331,12 @@ class ProxyLoggingMiddleware(object): try: iterable = self.app(env, my_start_response) except Exception: - exc_type, exc_value, exc_traceback = sys.exc_info() req = Request(env) status_int = status_int_for_logging(start_status=500) self.log_request( req, status_int, input_proxy.bytes_received, 0, start_time, time.time()) - six.reraise(exc_type, exc_value, exc_traceback) + raise else: return iter_response(iterable) diff --git a/swift/common/middleware/s3api/acl_handlers.py b/swift/common/middleware/s3api/acl_handlers.py index ad563dad7e..dade81cec5 100644 --- a/swift/common/middleware/s3api/acl_handlers.py +++ b/swift/common/middleware/s3api/acl_handlers.py @@ -49,8 +49,6 @@ Example:: the end of method. """ -import sys - from swift.common.middleware.s3api.subresource import ACL, Owner, encode_acl from swift.common.middleware.s3api.s3response import MissingSecurityHeader, \ MalformedACLError, UnexpectedContent @@ -168,9 +166,8 @@ class BaseAclHandler(object): except(XMLSyntaxError, DocumentInvalid): raise MalformedACLError() except Exception as e: - exc_type, exc_value, exc_traceback = sys.exc_info() self.logger.error(e) - raise exc_type, exc_value, exc_traceback + raise else: if body: # Specifying grant with both header and xml is not allowed. diff --git a/swift/common/middleware/s3api/controllers/bucket.py b/swift/common/middleware/s3api/controllers/bucket.py index df80684937..d57d8800fb 100644 --- a/swift/common/middleware/s3api/controllers/bucket.py +++ b/swift/common/middleware/s3api/controllers/bucket.py @@ -13,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import sys from base64 import standard_b64encode as b64encode from base64 import standard_b64decode as b64decode @@ -218,9 +217,8 @@ class BucketController(Controller): except (XMLSyntaxError, DocumentInvalid): raise MalformedXML() except Exception as e: - exc_type, exc_value, exc_traceback = sys.exc_info() self.logger.error(e) - raise exc_type, exc_value, exc_traceback + raise if location != self.conf.location: # s3api cannot support multiple regions currently. diff --git a/swift/common/middleware/s3api/controllers/multi_delete.py b/swift/common/middleware/s3api/controllers/multi_delete.py index a4326dd334..a7e95a7bdf 100644 --- a/swift/common/middleware/s3api/controllers/multi_delete.py +++ b/swift/common/middleware/s3api/controllers/multi_delete.py @@ -13,8 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import sys - from swift.common.utils import public from swift.common.middleware.s3api.controllers.base import Controller, \ @@ -85,9 +83,8 @@ class MultiObjectDeleteController(Controller): except ErrorResponse: raise except Exception as e: - exc_type, exc_value, exc_traceback = sys.exc_info() self.logger.error(e) - raise exc_type, exc_value, exc_traceback + raise elem = Element('DeleteResult') diff --git a/swift/common/middleware/s3api/controllers/multi_upload.py b/swift/common/middleware/s3api/controllers/multi_upload.py index 384dc675ee..626a36204d 100644 --- a/swift/common/middleware/s3api/controllers/multi_upload.py +++ b/swift/common/middleware/s3api/controllers/multi_upload.py @@ -61,7 +61,6 @@ Static Large Object when the multipart upload is completed. import os import re -import sys from swift.common.swob import Range from swift.common.utils import json, public @@ -605,9 +604,8 @@ class UploadController(Controller): except ErrorResponse: raise except Exception as e: - exc_type, exc_value, exc_traceback = sys.exc_info() self.logger.error(e) - raise exc_type, exc_value, exc_traceback + raise # Check the size of each segment except the last and make sure they are # all more than the minimum upload chunk size diff --git a/swift/common/middleware/s3api/controllers/obj.py b/swift/common/middleware/s3api/controllers/obj.py index 57e1fc5518..d466edd8f2 100644 --- a/swift/common/middleware/s3api/controllers/obj.py +++ b/swift/common/middleware/s3api/controllers/obj.py @@ -13,8 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import sys - from swift.common.http import HTTP_OK, HTTP_PARTIAL_CONTENT, HTTP_NO_CONTENT from swift.common.swob import Range, content_range_header_value from swift.common.utils import public @@ -144,7 +142,6 @@ class ObjectController(Controller): resp.body = '' except NoSuchKey: # expect to raise NoSuchBucket when the bucket doesn't exist - exc_type, exc_value, exc_traceback = sys.exc_info() req.get_container_info(self.app) - raise exc_type, exc_value, exc_traceback + raise return resp diff --git a/swift/common/middleware/s3api/etree.py b/swift/common/middleware/s3api/etree.py index 386e1bd767..e81af15133 100644 --- a/swift/common/middleware/s3api/etree.py +++ b/swift/common/middleware/s3api/etree.py @@ -18,7 +18,6 @@ from urllib import quote from copy import deepcopy from pkg_resources import resource_stream # pylint: disable-msg=E0611 import six -import sys from swift.common.utils import get_logger from swift.common.middleware.s3api.exception import S3Exception @@ -76,10 +75,9 @@ def fromstring(text, root_tag=None, logger=None): lxml.etree.RelaxNG(file=rng).assertValid(elem) except IOError as e: # Probably, the schema file doesn't exist. - exc_type, exc_value, exc_traceback = sys.exc_info() logger = logger or get_logger({}, log_route='s3api') logger.error(e) - raise exc_type, exc_value, exc_traceback + raise except lxml.etree.DocumentInvalid as e: if logger: logger.debug(e) diff --git a/swift/proxy/controllers/base.py b/swift/proxy/controllers/base.py index 4822b01729..1775a33731 100644 --- a/swift/proxy/controllers/base.py +++ b/swift/proxy/controllers/base.py @@ -973,7 +973,7 @@ class ResumingGetter(object): except ChunkReadTimeout: exc_type, exc_value, exc_traceback = exc_info() if self.newest or self.server_type != 'Object': - six.reraise(exc_type, exc_value, exc_traceback) + raise try: self.fast_forward(self.bytes_used_from_backend) except (HTTPException, ValueError): @@ -1091,20 +1091,18 @@ class ResumingGetter(object): self.app.client_timeout) self.app.logger.increment('client_timeouts') except GeneratorExit: - exc_type, exc_value, exc_traceback = exc_info() warn = True - try: - req_range = Range(self.backend_headers['Range']) - except ValueError: - req_range = None - if req_range and len(req_range.ranges) == 1: - begin, end = req_range.ranges[0] - if end is not None and begin is not None: - if end - begin + 1 == self.bytes_used_from_backend: - warn = False + req_range = self.backend_headers['Range'] + if req_range: + req_range = Range(req_range) + if len(req_range.ranges) == 1: + begin, end = req_range.ranges[0] + if end is not None and begin is not None: + if end - begin + 1 == self.bytes_used_from_backend: + warn = False if not req.environ.get('swift.non_client_disconnect') and warn: self.app.logger.warning(_('Client disconnected on read')) - six.reraise(exc_type, exc_value, exc_traceback) + raise except Exception: self.app.logger.exception(_('Trying to send to client')) raise