Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(36)

Delta Between Two Patch Sets: Lib/asyncio/selector_events.py

Issue 27906: Socket accept exhaustion during high TCP traffic
Left Patch Set: Created 3 years, 5 months ago
Right Patch Set: Created 3 years, 5 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/asyncio/base_events.py ('k') | Lib/test/test_asyncio/test_base_events.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 """Event loop using a selector and related classes. 1 """Event loop using a selector and related classes.
2 2
3 A selector is a "notify-when-ready" multiplexer. For a subclass which 3 A selector is a "notify-when-ready" multiplexer. For a subclass which
4 also includes support for signal handling, see the unix_events sub-module. 4 also includes support for signal handling, see the unix_events sub-module.
5 """ 5 """
6 6
7 __all__ = ['BaseSelectorEventLoop'] 7 __all__ = ['BaseSelectorEventLoop']
8 8
9 import collections 9 import collections
10 import errno 10 import errno
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 "self-pipe socket", 150 "self-pipe socket",
151 exc_info=True) 151 exc_info=True)
152 152
153 def _start_serving(self, protocol_factory, sock, 153 def _start_serving(self, protocol_factory, sock,
154 sslcontext=None, server=None, backlog=100): 154 sslcontext=None, server=None, backlog=100):
155 self.add_reader(sock.fileno(), self._accept_connection, 155 self.add_reader(sock.fileno(), self._accept_connection,
156 protocol_factory, sock, sslcontext, server, backlog) 156 protocol_factory, sock, sslcontext, server, backlog)
157 157
158 def _accept_connection(self, protocol_factory, sock, 158 def _accept_connection(self, protocol_factory, sock,
159 sslcontext=None, server=None, backlog=100): 159 sslcontext=None, server=None, backlog=100):
160 # This method is only called once for each event loop tick where the
161 # listening socket has triggered an EVENT_READ. There may be multiple
162 # connections waiting for an .accept() so it is called in a loop.
163 # See https://bugs.python.org/issue27906 for more details.
160 for _ in range(backlog): 164 for _ in range(backlog):
AntoinePitrou 2016/08/31 10:53:30 Add a comment (with issue #) explaining why the ra
161 try: 165 try:
162 conn, addr = sock.accept() 166 conn, addr = sock.accept()
163 if self._debug: 167 if self._debug:
164 logger.debug("%r got a new connection from %r: %r", 168 logger.debug("%r got a new connection from %r: %r",
165 server, addr, conn) 169 server, addr, conn)
166 conn.setblocking(False) 170 conn.setblocking(False)
167 except (BlockingIOError, InterruptedError, ConnectionAbortedError): 171 except (BlockingIOError, InterruptedError, ConnectionAbortedError):
168 # Early exit because the socket accept buffer is empty. 172 # Early exit because the socket accept buffer is empty.
169 return None 173 return None
170 except OSError as exc: 174 except OSError as exc:
(...skipping 912 matching lines...) Expand 10 before | Expand all | Expand 10 after
1083 except Exception as exc: 1087 except Exception as exc:
1084 self._fatal_error(exc, 1088 self._fatal_error(exc,
1085 'Fatal write error on datagram transport') 1089 'Fatal write error on datagram transport')
1086 return 1090 return
1087 1091
1088 self._maybe_resume_protocol() # May append to buffer. 1092 self._maybe_resume_protocol() # May append to buffer.
1089 if not self._buffer: 1093 if not self._buffer:
1090 self._loop.remove_writer(self._sock_fd) 1094 self._loop.remove_writer(self._sock_fd)
1091 if self._closing: 1095 if self._closing:
1092 self._call_connection_lost(None) 1096 self._call_connection_lost(None)
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+