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
3 changes: 3 additions & 0 deletions docs/versionhistory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ This library adheres to `Semantic Versioning 2.0 <http://semver.org/>`_.
- Fixed ``UNIXSocketStream.aclose()`` raising ``asyncio.InvalidStateError`` when a
concurrent receive or send operation had just been cancelled on the asyncio backend
(`#1267 <https://github.com/agronholm/anyio/issues/1267>`_; PR by @alloutflo)
- Fixed socket ``aclose()`` implementations not checkpointing after closing on the
asyncio and Trio backends
(`#1288 <https://github.com/agronholm/anyio/issues/1288>`_; PR by @hansu650)
- Fixed the pytest plugin importing the deprecated ``_pytest.python.CallSpec2`` alias,
which triggers ``PytestRemovedIn10Warning`` on ``pytest>=9.2`` and crashes pytest at
startup when ``filterwarnings = error`` is configured
Expand Down
2 changes: 2 additions & 0 deletions src/anyio/_backends/_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -1453,6 +1453,8 @@ async def aclose(self) -> None:
if self._send_future and not self._send_future.done():
self._send_future.set_result(None)

await AsyncIOBackend.checkpoint()


class UNIXSocketStream(_RawSocketMixin, abc.UNIXSocketStream):
async def send_eof(self) -> None:
Expand Down
2 changes: 2 additions & 0 deletions src/anyio/_backends/_trio.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,8 @@ async def aclose(self) -> None:
self._closed = True
self._trio_socket.close()

await trio.lowlevel.checkpoint()

def _convert_socket_error(self, exc: BaseException) -> NoReturn:
if isinstance(exc, trio.ClosedResourceError):
raise ClosedResourceError from exc
Expand Down
15 changes: 15 additions & 0 deletions tests/test_sockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from anyio import (
BrokenResourceError,
BusyResourceError,
CancelScope,
ClosedResourceError,
EndOfStream,
Event,
Expand All @@ -54,6 +55,7 @@
create_unix_datagram_socket,
create_unix_listener,
fail_after,
get_cancelled_exc_class,
getaddrinfo,
getnameinfo,
move_on_after,
Expand Down Expand Up @@ -1499,6 +1501,19 @@ async def operate() -> None:
if client is not None:
await client.aclose()

async def test_aclose_checkpoints_when_cancelled(
self, server_sock: socket.socket, socket_path: Path
) -> None:
stream = await connect_unix(socket_path)
raw_socket = stream.extra(SocketAttribute.raw_socket)

with CancelScope() as scope:
scope.cancel()
with pytest.raises(get_cancelled_exc_class()):
await stream.aclose()

assert raw_socket.fileno() == -1

async def test_receive_after_close(
self, server_sock: socket.socket, socket_path: Path
) -> None:
Expand Down
Loading