summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_wsgiref.py18
-rw-r--r--Lib/wsgiref/handlers.py4
2 files changed, 22 insertions, 0 deletions
diff --git a/Lib/test/test_wsgiref.py b/Lib/test/test_wsgiref.py
index 737dfed..46f88a9 100644
--- a/Lib/test/test_wsgiref.py
+++ b/Lib/test/test_wsgiref.py
@@ -788,6 +788,24 @@ class HandlerTests(TestCase):
b"Hello, world!",
written)
+ def testClientConnectionTerminations(self):
+ environ = {"SERVER_PROTOCOL": "HTTP/1.0"}
+ for exception in (
+ ConnectionAbortedError,
+ BrokenPipeError,
+ ConnectionResetError,
+ ):
+ with self.subTest(exception=exception):
+ class AbortingWriter:
+ def write(self, b):
+ raise exception
+
+ stderr = StringIO()
+ h = SimpleHandler(BytesIO(), AbortingWriter(), stderr, environ)
+ h.run(hello_app)
+
+ self.assertFalse(stderr.getvalue())
+
if __name__ == "__main__":
unittest.main()
diff --git a/Lib/wsgiref/handlers.py b/Lib/wsgiref/handlers.py
index 28ed9b7..834073d 100644
--- a/Lib/wsgiref/handlers.py
+++ b/Lib/wsgiref/handlers.py
@@ -136,6 +136,10 @@ class BaseHandler:
self.setup_environ()
self.result = application(self.environ, self.start_response)
self.finish_response()
+ except (ConnectionAbortedError, BrokenPipeError, ConnectionResetError):
+ # We expect the client to close the connection abruptly from time
+ # to time.
+ return
except:
try:
self.handle_error()