mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
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.
This commit is contained in:
parent
47c0b1f7d4
commit
2a2247ce5e
1 changed files with 11 additions and 0 deletions
|
@ -362,6 +362,17 @@ class _UnixSelectorEventLoop(selector_events.BaseSelectorEventLoop):
|
||||||
fd, sock, fileno,
|
fd, sock, fileno,
|
||||||
offset, count, blocksize, total_sent)
|
offset, count, blocksize, total_sent)
|
||||||
except OSError as exc:
|
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:
|
if total_sent == 0:
|
||||||
# We can get here for different reasons, the main
|
# We can get here for different reasons, the main
|
||||||
# one being 'file' is not a regular mmap(2)-like
|
# one being 'file' is not a regular mmap(2)-like
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue