concurrent anyio.aclose_forcefully fails to block until socket is closed on asyncio
- 主要言語
- Python
- スター
- 2.5k
- フォーク
- 260
- 平均マージ
- 2日 8時間
- マージ済み PR(30日)
- 19
説明
### Things to check first
- [x] I have searched the existing issues and didn't find my bug already reported there
- [x] I have checked that my bug is still present in the latest release
### AnyIO version
f982b24986eac1ca8f34c91b0fdbaff8c378ba85
### Python version
3.12
### What happened?
Running the following tests fail on asyncio
```patch
From 267d773d30a63b9a22b6c389d7c099616e116628 Mon Sep 17 00:00:00 2001
From: Thomas Grainger
Date: Wed, 12 Aug 2026 21:30:48 +0100
Subject: [PATCH] add
test_concurrent_aclose_forcefully_returns_before_socket_closes
---
tests/test_sockets.py | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/tests/test_sockets.py b/tests/test_sockets.py
index f475676..b1213ee 100644
--- a/tests/test_sockets.py
+++ b/tests/test_sockets.py
@@ -43,6 +43,7 @@ from anyio import (
TCPConnectable,
TypedAttributeLookupError,
UNIXConnectable,
+ aclose_forcefully,
as_connectable,
connect_tcp,
connect_unix,
@@ -507,6 +508,23 @@ class TestTCPStream:
with pytest.raises(ClosedResourceError):
await stream.receive()
+ async def test_concurrent_aclose_forcefully_returns_before_socket_closes(
+ self, server_addr: tuple[str, int]
+ ) -> None:
+ stream = await connect_tcp(*server_addr)
+ raw_socket = stream.extra(SocketAttribute.raw_socket)
+ fds: list[int] = []
+
+ async def do_aclose() -> None:
+ await aclose_forcefully(stream)
+ fds.append(raw_socket.fileno())
+
+ async with create_task_group() as tg:
+ tg.start_soon(do_aclose)
+ tg.start_soon(do_aclose)
+
+ assert fds == [-1, -1]
+
async def test_receive_after_close(self, server_addr: tuple[str, int]) -> None:
stream = await connect_tcp(*server_addr)
await stream.aclose()
--
2.43.0
```
gets
```
FAILED tests/test_sockets.py::TestTCPStream::test_concurrent_aclose_forcefully_returns_before_socket_closes[asyncio-ipv4] - assert [15, -1] == [-1, -1]
FAILED tests/test_sockets.py::TestTCPStream::test_concurrent_aclose_forcefully_returns_before_socket_closes[asyncio-ipv6] - assert [15, -1] == [-1, -1]
FAILED tests/test_sockets.py::TestTCPStream::test_concurrent_aclose_forcefully_returns_before_socket_closes[asyncio+uvloop-ipv4] - assert [23, -1] == [-1, -1]
FAILED tests/test_sockets.py::TestTCPStream::test_concurrent_aclose_forcefully_returns_before_socket_closes[asyncio+uvloop-ipv6] - assert [23, -1] == [-1, -1]
FAILED tests/test_sockets.py::TestTCPStream::test_concurrent_aclose_forcefully_returns_before_socket_closes[asyncio+eager-ipv4] - assert [17, -1] == [-1, -1]
FAILED tests/test_sockets.py::TestTCPStream::test_concurrent_aclose_forcefully_returns_before_socket_closes[asyncio+eager-ipv6] - assert [17, -1] == [-1, -1]
```
### How can we reproduce the bug?
see above
コントリビューションガイド
調査の方向性
Start with aclose_forcefully and the failing test_concurrent_aclose_forcefully_returns_before_socket_closes in tests/test_sockets.py. Run that test across the listed asyncio, uvloop, and eager variants, then trace the close behavior until both concurrent calls observe a closed socket; done means the test passes without regressing the surrounding TCP stream tests.
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- networking, testing-qa
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 活発
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 74/100