Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2a2247c

Browse files
authored
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.
1 parent 47c0b1f commit 2a2247c

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

Lib/asyncio/unix_events.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,17 @@ def _sock_sendfile_native_impl(self, fut, registered_fd, sock, fileno,
362362
fd, sock, fileno,
363363
offset, count, blocksize, total_sent)
364364
except OSError as exc:
365+
if (registered_fd is not None and
366+
exc.errno == errno.ENOTCONN and
367+
type(exc) is not ConnectionError):
368+
# If we have an ENOTCONN and this isn't a first call to
369+
# sendfile(), i.e. the connection was closed in the middle
370+
# of the operation, normalize the error to ConnectionError
371+
# to make it consistent across all Posix systems.
372+
new_exc = ConnectionError(
373+
"socket is not connected", errno.ENOTCONN)
374+
new_exc.__cause__ = exc
375+
exc = new_exc
365376
if total_sent == 0:
366377
# We can get here for different reasons, the main
367378
# one being 'file' is not a regular mmap(2)-like

0 commit comments

Comments
 (0)