Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f1a9d89

Browse filesBrowse files
miss-islingtonChristianHrsambvkumaraditya303
authored
[3.14] gh-90871: fix connection backlog offset in asyncio (gh-134392) (gh-134421)
(cherry picked from commit 109f759) Co-authored-by: Christian Harries <68507104+ChristianHrs@users.noreply.github.com> Co-authored-by: Łukasz Langa <lukasz@langa.pl> Co-authored-by: Kumar Aditya <kumaraditya@python.org>
1 parent 9be568e commit f1a9d89
Copy full SHA for f1a9d89

File tree

3 files changed

+17
-3
lines changed
Filter options

3 files changed

+17
-3
lines changed

‎Lib/asyncio/selector_events.py

Copy file name to clipboardExpand all lines: Lib/asyncio/selector_events.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def _accept_connection(
173173
# listening socket has triggered an EVENT_READ. There may be multiple
174174
# connections waiting for an .accept() so it is called in a loop.
175175
# See https://bugs.python.org/issue27906 for more details.
176-
for _ in range(backlog):
176+
for _ in range(backlog + 1):
177177
try:
178178
conn, addr = sock.accept()
179179
if self._debug:

‎Lib/test/test_asyncio/test_selector_events.py

Copy file name to clipboardExpand all lines: Lib/test/test_asyncio/test_selector_events.py
+14-2Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,18 @@ def test_process_events_write_cancelled(self):
347347
selectors.EVENT_WRITE)])
348348
self.loop._remove_writer.assert_called_with(1)
349349

350+
def test_accept_connection_zero_one(self):
351+
for backlog in [0, 1]:
352+
sock = mock.Mock()
353+
sock.accept.return_value = (mock.Mock(), mock.Mock())
354+
with self.subTest(backlog):
355+
mock_obj = mock.patch.object
356+
with mock_obj(self.loop, '_accept_connection2') as accept2_mock:
357+
self.loop._accept_connection(
358+
mock.Mock(), sock, backlog=backlog)
359+
self.loop.run_until_complete(asyncio.sleep(0))
360+
self.assertEqual(sock.accept.call_count, backlog + 1)
361+
350362
def test_accept_connection_multiple(self):
351363
sock = mock.Mock()
352364
sock.accept.return_value = (mock.Mock(), mock.Mock())
@@ -362,7 +374,7 @@ def test_accept_connection_multiple(self):
362374
self.loop._accept_connection(
363375
mock.Mock(), sock, backlog=backlog)
364376
self.loop.run_until_complete(asyncio.sleep(0))
365-
self.assertEqual(sock.accept.call_count, backlog)
377+
self.assertEqual(sock.accept.call_count, backlog + 1)
366378

367379
def test_accept_connection_skip_connectionabortederror(self):
368380
sock = mock.Mock()
@@ -388,7 +400,7 @@ def mock_sock_accept():
388400
# as in test_accept_connection_multiple avoid task pending
389401
# warnings by using asyncio.sleep(0)
390402
self.loop.run_until_complete(asyncio.sleep(0))
391-
self.assertEqual(sock.accept.call_count, backlog)
403+
self.assertEqual(sock.accept.call_count, backlog + 1)
392404

393405
class SelectorTransportTests(test_utils.TestCase):
394406

+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fixed an off by one error concerning the backlog parameter in
2+
:meth:`~asyncio.loop.create_unix_server`. Contributed by Christian Harries.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.