Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitf1a9d89

Browse files
miss-islingtonChristianHrsambvkumaraditya303
authored
[3.14]gh-90871: fix connection backlog offset in asyncio (gh-134392) (gh-134421)
(cherry picked from commit109f759)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 parent9be568e commitf1a9d89

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

‎Lib/asyncio/selector_events.py

Lines 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_inrange(backlog):
176+
for_inrange(backlog+1):
177177
try:
178178
conn,addr=sock.accept()
179179
ifself._debug:

‎Lib/test/test_asyncio/test_selector_events.py

Lines 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+
deftest_accept_connection_zero_one(self):
351+
forbacklogin [0,1]:
352+
sock=mock.Mock()
353+
sock.accept.return_value= (mock.Mock(),mock.Mock())
354+
withself.subTest(backlog):
355+
mock_obj=mock.patch.object
356+
withmock_obj(self.loop,'_accept_connection2')asaccept2_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
deftest_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
deftest_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
classSelectorTransportTests(test_utils.TestCase):
394406

Lines 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)

[8]ページ先頭

©2009-2025 Movatter.jp