Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch ConnectionError instead of socket.error on Python 3 #1418

Merged
merged 1 commit into from Dec 10, 2018
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -178,6 +178,9 @@ Unreleased

- :func:`~http.parse_options_header` understands :rfc:`2231` parameter
continuations. (`#1417`_)
- The development server recognizes ``ConnectionError`` on Python 3 to
silence client disconnects, and does not silence other ``OSErrors``
that may have been raised inside the application. (`#1418`_)

.. _#4: https://github.com/pallets/werkzeug/issues/4
.. _`#209`: https://github.com/pallets/werkzeug/pull/209
@@ -237,6 +240,7 @@ Unreleased
.. _#1413: https://github.com/pallets/werkzeug/pull/1413
.. _#1416: https://github.com/pallets/werkzeug/pull/1416
.. _#1417: https://github.com/pallets/werkzeug/pull/1417
.. _#1418: https://github.com/pallets/werkzeug/pull/1418
Version 0.14.1
@@ -103,6 +103,14 @@ class ForkingMixIn(object):
LISTEN_QUEUE = 128
can_open_by_fd = not WIN and hasattr(socket, 'fromfd')

# On Python 3, ConnectionError represents the same errnos as
# socket.error from Python 2, while socket.error is an alias for the
# more generic OSError.
if PY2:
_ConnectionError = socket.error
else:
_ConnectionError = ConnectionError


class DechunkedInput(io.RawIOBase):
"""An input stream that handles Transfer-Encoding 'chunked'"""
@@ -282,7 +290,7 @@ def execute(app):

try:
execute(self.server.app)
except (socket.error, socket.timeout) as e:
except (_ConnectionError, socket.timeout) as e:
self.connection_dropped(e, environ)
except Exception:
if self.server.passthrough_errors:
@@ -305,10 +313,10 @@ def handle(self):
rv = None
try:
rv = BaseHTTPRequestHandler.handle(self)
except (socket.error, socket.timeout) as e:
except (_ConnectionError, socket.timeout) as e:
self.connection_dropped(e)
except Exception:
if self.server.ssl_context is None or not is_ssl_error():
except Exception as e:
if self.server.ssl_context is None or not is_ssl_error(e):
raise
if self.server.shutdown_signal:
self.initiate_shutdown()
@@ -681,6 +689,10 @@ def serve_forever(self):
def handle_error(self, request, client_address):
if self.passthrough_errors:
raise
# Python 2 still causes a socket.error after the earlier
# handling, so silence it here.
if isinstance(sys.exc_info()[1], _ConnectionError):
return
return HTTPServer.handle_error(self, request, client_address)

def get_request(self):
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.