diff options
author | Yury Selivanov <yury@magic.io> | 2018-01-27 22:22:01 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-27 22:22:01 (GMT) |
commit | 2a2247ce5e1984eb2f2c41b269b38dbb795a60cf (patch) | |
tree | 218825a29cd6a02cf471c04d79bfb4252da606f9 /Lib/asyncio | |
parent | 47c0b1f7d4115e6f15e6776c1f91d28e7d96fe0c (diff) | |
download | cpython-2a2247ce5e1984eb2f2c41b269b38dbb795a60cf.zip cpython-2a2247ce5e1984eb2f2c41b269b38dbb795a60cf.tar.gz cpython-2a2247ce5e1984eb2f2c41b269b38dbb795a60cf.tar.bz2 |
bpo-32622: Normalize ENOTCONN to ConnectionError on macOS (GH-5369)
On mac, sendfile throws ENOTCONN on a repeated sendfile call if
the connection is closed. Normalize it to behave like other systems.
Diffstat (limited to 'Lib/asyncio')
-rw-r--r-- | Lib/asyncio/unix_events.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py index a4d892a..6cac137 100644 --- a/Lib/asyncio/unix_events.py +++ b/Lib/asyncio/unix_events.py @@ -362,6 +362,17 @@ class _UnixSelectorEventLoop(selector_events.BaseSelectorEventLoop): fd, sock, fileno, offset, count, blocksize, total_sent) except OSError as exc: + if (registered_fd is not None and + exc.errno == errno.ENOTCONN and + type(exc) is not ConnectionError): + # If we have an ENOTCONN and this isn't a first call to + # sendfile(), i.e. the connection was closed in the middle + # of the operation, normalize the error to ConnectionError + # to make it consistent across all Posix systems. + new_exc = ConnectionError( + "socket is not connected", errno.ENOTCONN) + new_exc.__cause__ = exc + exc = new_exc if total_sent == 0: # We can get here for different reasons, the main # one being 'file' is not a regular mmap(2)-like |