Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions Lib/asyncio/selector_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
import weakref
try:
import ssl
RECOVERABLE_ERRORS = (BlockingIOError, InterruptedError, ssl.SSLWantReadError, ssl.SSLWantWriteError)
except ImportError: # pragma: no cover
ssl = None
RECOVERABLE_ERRORS = (BlockingIOError, InterruptedError)

from . import base_events
from . import constants
Expand Down Expand Up @@ -362,7 +364,7 @@ async def sock_recv(self, sock, n):
raise ValueError("the socket must be non-blocking")
try:
return sock.recv(n)
except (BlockingIOError, InterruptedError):
except RECOVERABLE_ERRORS:
pass
fut = self.create_future()
fd = sock.fileno()
Expand All @@ -383,7 +385,7 @@ def _sock_recv(self, fut, sock, n):
return
try:
data = sock.recv(n)
except (BlockingIOError, InterruptedError):
except RECOVERABLE_ERRORS:
return # try again next time
except (SystemExit, KeyboardInterrupt):
raise
Expand All @@ -403,7 +405,7 @@ async def sock_recv_into(self, sock, buf):
raise ValueError("the socket must be non-blocking")
try:
return sock.recv_into(buf)
except (BlockingIOError, InterruptedError):
except RECOVERABLE_ERRORS:
pass
fut = self.create_future()
fd = sock.fileno()
Expand All @@ -421,7 +423,7 @@ def _sock_recv_into(self, fut, sock, buf):
return
try:
nbytes = sock.recv_into(buf)
except (BlockingIOError, InterruptedError):
except RECOVERABLE_ERRORS:
return # try again next time
except (SystemExit, KeyboardInterrupt):
raise
Expand All @@ -444,7 +446,7 @@ async def sock_sendall(self, sock, data):
raise ValueError("the socket must be non-blocking")
try:
n = sock.send(data)
except (BlockingIOError, InterruptedError):
except RECOVERABLE_ERRORS:
n = 0

if n == len(data):
Expand All @@ -468,7 +470,7 @@ def _sock_sendall(self, fut, sock, view, pos):
start = pos[0]
try:
n = sock.send(view[start:])
except (BlockingIOError, InterruptedError):
except RECOVERABLE_ERRORS:
return
except (SystemExit, KeyboardInterrupt):
raise
Expand Down Expand Up @@ -505,7 +507,7 @@ def _sock_connect(self, fut, sock, address):
fd = sock.fileno()
try:
sock.connect(address)
except (BlockingIOError, InterruptedError):
except RECOVERABLE_ERRORS:
# Issue #23618: When the C function connect() fails with EINTR, the
# connection runs in background. We have to wait until the socket
# becomes writable to be notified when the connection succeed or
Expand Down Expand Up @@ -535,7 +537,7 @@ def _sock_connect_cb(self, fut, sock, address):
if err != 0:
# Jump to any except clause below.
raise OSError(err, f'Connect call failed {address}')
except (BlockingIOError, InterruptedError):
except RECOVERABLE_ERRORS:
# socket is still registered, the callback will be retried later
pass
except (SystemExit, KeyboardInterrupt):
Expand Down Expand Up @@ -565,7 +567,7 @@ def _sock_accept(self, fut, sock):
try:
conn, address = sock.accept()
conn.setblocking(False)
except (BlockingIOError, InterruptedError):
except RECOVERABLE_ERRORS:
self._ensure_fd_no_transport(fd)
handle = self._add_reader(fd, self._sock_accept, fut, sock)
fut.add_done_callback(
Expand Down Expand Up @@ -829,7 +831,7 @@ def _read_ready__get_buffer(self):

try:
nbytes = self._sock.recv_into(buf)
except (BlockingIOError, InterruptedError):
except RECOVERABLE_ERRORS:
return
except (SystemExit, KeyboardInterrupt):
raise
Expand All @@ -854,7 +856,7 @@ def _read_ready__data_received(self):
return
try:
data = self._sock.recv(self.max_size)
except (BlockingIOError, InterruptedError):
except RECOVERABLE_ERRORS:
return
except (SystemExit, KeyboardInterrupt):
raise
Expand Down Expand Up @@ -916,7 +918,7 @@ def write(self, data):
# Optimization: try to send now.
try:
n = self._sock.send(data)
except (BlockingIOError, InterruptedError):
except RECOVERABLE_ERRORS:
pass
except (SystemExit, KeyboardInterrupt):
raise
Expand All @@ -941,7 +943,7 @@ def _write_ready(self):
return
try:
n = self._sock.send(self._buffer)
except (BlockingIOError, InterruptedError):
except RECOVERABLE_ERRORS:
pass
except (SystemExit, KeyboardInterrupt):
raise
Expand Down Expand Up @@ -1017,7 +1019,7 @@ def _read_ready(self):
return
try:
data, addr = self._sock.recvfrom(self.max_size)
except (BlockingIOError, InterruptedError):
except RECOVERABLE_ERRORS:
pass
except OSError as exc:
self._protocol.error_received(exc)
Expand Down Expand Up @@ -1055,7 +1057,7 @@ def sendto(self, data, addr=None):
else:
self._sock.sendto(data, addr)
return
except (BlockingIOError, InterruptedError):
except RECOVERABLE_ERRORS:
self._loop._add_writer(self._sock_fd, self._sendto_ready)
except OSError as exc:
self._protocol.error_received(exc)
Expand All @@ -1079,7 +1081,7 @@ def _sendto_ready(self):
self._sock.send(data)
else:
self._sock.sendto(data, addr)
except (BlockingIOError, InterruptedError):
except RECOVERABLE_ERRORS:
self._buffer.appendleft((data, addr)) # Try again later.
break
except OSError as exc:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Prevent ``asyncio`` socket transport from closing on ``SSLWantReadError`` and ``SSLWantWriteError``.