mirror of
https://github.com/django/django.git
synced 2024-12-22 17:16:24 +00:00
Fixed #32240 -- Made runserver suppress ConnectionAbortedError/ConnectionResetError errors.
See https://bugs.python.org/issue27682 and https://github.com/python/cpython/pull/9713
This commit is contained in:
parent
28124e7bdf
commit
772eca0b02
1
AUTHORS
1
AUTHORS
@ -736,6 +736,7 @@ answer newbie questions, and generally made Django that much better:
|
|||||||
Peter Zsoldos <http://zsoldosp.eu>
|
Peter Zsoldos <http://zsoldosp.eu>
|
||||||
Pete Shinners <pete@shinners.org>
|
Pete Shinners <pete@shinners.org>
|
||||||
Petr Marhoun <petr.marhoun@gmail.com>
|
Petr Marhoun <petr.marhoun@gmail.com>
|
||||||
|
Petter Strandmark
|
||||||
pgross@thoughtworks.com
|
pgross@thoughtworks.com
|
||||||
phaedo <http://phaedo.cx/>
|
phaedo <http://phaedo.cx/>
|
||||||
phil.h.smith@gmail.com
|
phil.h.smith@gmail.com
|
||||||
|
@ -52,7 +52,11 @@ def get_internal_wsgi_application():
|
|||||||
|
|
||||||
def is_broken_pipe_error():
|
def is_broken_pipe_error():
|
||||||
exc_type, _, _ = sys.exc_info()
|
exc_type, _, _ = sys.exc_info()
|
||||||
return issubclass(exc_type, BrokenPipeError)
|
return issubclass(exc_type, (
|
||||||
|
BrokenPipeError,
|
||||||
|
ConnectionAbortedError,
|
||||||
|
ConnectionResetError,
|
||||||
|
))
|
||||||
|
|
||||||
|
|
||||||
class WSGIServer(simple_server.WSGIServer):
|
class WSGIServer(simple_server.WSGIServer):
|
||||||
|
@ -113,15 +113,22 @@ class WSGIServerTestCase(SimpleTestCase):
|
|||||||
request = WSGIRequest(self.request_factory.get('/').environ)
|
request = WSGIRequest(self.request_factory.get('/').environ)
|
||||||
client_address = ('192.168.2.0', 8080)
|
client_address = ('192.168.2.0', 8080)
|
||||||
msg = f'- Broken pipe from {client_address}\n'
|
msg = f'- Broken pipe from {client_address}\n'
|
||||||
try:
|
tests = [
|
||||||
server = WSGIServer(('localhost', 0), WSGIRequestHandler)
|
BrokenPipeError,
|
||||||
try:
|
ConnectionAbortedError,
|
||||||
raise BrokenPipeError()
|
ConnectionResetError,
|
||||||
except Exception:
|
]
|
||||||
with captured_stderr() as err:
|
for exception in tests:
|
||||||
with self.assertLogs('django.server', 'INFO') as cm:
|
with self.subTest(exception=exception):
|
||||||
server.handle_error(request, client_address)
|
try:
|
||||||
self.assertEqual(err.getvalue(), '')
|
server = WSGIServer(('localhost', 0), WSGIRequestHandler)
|
||||||
self.assertEqual(cm.records[0].getMessage(), msg)
|
try:
|
||||||
finally:
|
raise exception()
|
||||||
server.server_close()
|
except Exception:
|
||||||
|
with captured_stderr() as err:
|
||||||
|
with self.assertLogs('django.server', 'INFO') as cm:
|
||||||
|
server.handle_error(request, client_address)
|
||||||
|
self.assertEqual(err.getvalue(), '')
|
||||||
|
self.assertEqual(cm.records[0].getMessage(), msg)
|
||||||
|
finally:
|
||||||
|
server.server_close()
|
||||||
|
Loading…
Reference in New Issue
Block a user