Skip to content

Commit

Permalink
Skip BrokenPipeError test on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
sethmlarson committed Aug 28, 2020
1 parent 4a7040c commit c6ae228
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
10 changes: 7 additions & 3 deletions src/urllib3/connectionpool.py
Expand Up @@ -400,10 +400,14 @@ def _make_request(
# Python 3
pass
except IOError as e:
# EPIPE and ESHUTDOWN are BrokenPipeError on Python 2, and EPROTOTYPE is
# needed on macOS
# Python 2 and macOS/Linux
# EPIPE and ESHUTDOWN are BrokenPipeError on Python 2, and EPROTOTYPE is needed on macOS
# https://erickt.github.io/blog/2014/11/19/adventures-in-debugging-a-potential-osx-kernel-bug/
if e.errno not in (errno.EPIPE, errno.ESHUTDOWN, errno.EPROTOTYPE):
if e.errno not in {
errno.EPIPE,
errno.ESHUTDOWN,
errno.EPROTOTYPE,
}:
raise

# Reset the timeout for the recv() on the socket
Expand Down
13 changes: 13 additions & 0 deletions test/__init__.py
Expand Up @@ -152,6 +152,19 @@ def wrapper(*args, **kwargs):
return wrapper


def notWindows(test):
"""Skips this test when running on Windows"""

@six.wraps(test)
def wrapper(*args, **kwargs):
msg = "{name} does not run on Windows".format(name=test.__name__)
if platform.system() == "Windows":
pytest.skip(msg)
return test(*args, **kwargs)

return wrapper


def notOpenSSL098(test):
"""Skips this test for Python 3.5 macOS python.org distribution"""

Expand Down
14 changes: 12 additions & 2 deletions test/with_dummyserver/test_socketlevel.py
Expand Up @@ -57,6 +57,7 @@ class MimeToolMessage(object):
LONG_TIMEOUT,
notPyPy2,
notSecureTransport,
notWindows,
resolvesLocalhostFQDN,
)

Expand Down Expand Up @@ -1783,7 +1784,10 @@ def socket_handler(listener):


class TestBrokenPipe(SocketDummyServerTestCase):
def test_broken_pipe_ignore(self, monkeypatch):
@notWindows
def test_ignore_broken_pipe_errors(self, monkeypatch):
# On Windows an aborted connection raises an error on
# attempts to read data out of a socket that's been closed.
sock_shut = Event()
orig_connect = HTTPConnection.connect
# a buffer that will cause two sendall calls
Expand All @@ -1800,8 +1804,9 @@ def socket_handler(listener):
sock.send(
b"HTTP/1.1 404 Not Found\r\n"
b"Connection: close\r\n"
b"Content-Length: 0\r\n"
b"Content-Length: 10\r\n"
b"\r\n"
b"xxxxxxxxxx"
)
sock.shutdown(socket.SHUT_RDWR)
sock_shut.set()
Expand All @@ -1812,5 +1817,10 @@ def socket_handler(listener):
with HTTPConnectionPool(self.host, self.port) as pool:
r = pool.request("POST", "/", body=buf)
assert r.status == 404
assert r.headers["content-length"] == "10"
assert r.data == b"xxxxxxxxxx"

r = pool.request("POST", "/admin", chunked=True, body=buf)
assert r.status == 404
assert r.headers["content-length"] == "10"
assert r.data == b"xxxxxxxxxx"

0 comments on commit c6ae228

Please sign in to comment.