diff options
author | Berker Peksag <berker.peksag@gmail.com> | 2019-05-19 15:56:15 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-19 15:56:15 (GMT) |
commit | 7c59362a15dfce538512ff1fce4e07d33a925cfb (patch) | |
tree | ab4a3d9933d81c3e5b227419fa1c39afae6c6d37 /Lib/wsgiref | |
parent | f4e1babf44792bdeb0c01da96821ba0800a51fd8 (diff) | |
download | cpython-7c59362a15dfce538512ff1fce4e07d33a925cfb.zip cpython-7c59362a15dfce538512ff1fce4e07d33a925cfb.tar.gz cpython-7c59362a15dfce538512ff1fce4e07d33a925cfb.tar.bz2 |
bpo-29183: Fix double exceptions in wsgiref.handlers.BaseHandler (GH-12914)
Diffstat (limited to 'Lib/wsgiref')
-rw-r--r-- | Lib/wsgiref/handlers.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/Lib/wsgiref/handlers.py b/Lib/wsgiref/handlers.py index 834073d..31360e5 100644 --- a/Lib/wsgiref/handlers.py +++ b/Lib/wsgiref/handlers.py @@ -183,7 +183,16 @@ class BaseHandler: for data in self.result: self.write(data) self.finish_content() - finally: + except: + # Call close() on the iterable returned by the WSGI application + # in case of an exception. + if hasattr(self.result, 'close'): + self.result.close() + raise + else: + # We only call close() when no exception is raised, because it + # will set status, result, headers, and environ fields to None. + # See bpo-29183 for more details. self.close() |