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
1 change: 1 addition & 0 deletions src/anyio/_backends/_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -1452,6 +1452,7 @@ async def aclose(self) -> None:
self._receive_future.set_result(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):
Expand Down
1 change: 1 addition & 0 deletions src/anyio/_backends/_trio.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ async def aclose(self) -> None:
if self._trio_socket.fileno() >= 0:
self._closed = True
self._trio_socket.close()
await trio.lowlevel.checkpoint()

def _convert_socket_error(self, exc: BaseException) -> NoReturn:
if isinstance(exc, trio.ClosedResourceError):
Expand Down
22 changes: 19 additions & 3 deletions tests/test_sockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1581,10 +1581,26 @@ async def test_from_socket_not_connected(
with pytest.raises(ValueError, match="the socket must be connected"):
await UNIXSocketStream.from_socket(sock_or_fd)

@pytest.mark.skipif(
sys.platform == "win32", reason="UNIX sockets are not available on Windows"
)
async def test_aclose_in_cancelled_scope_raises_cancelled_exc(
self, server_sock: socket.socket, socket_path: Path
) -> None:
exc = None
stream = await connect_unix(socket_path)

with CancelScope() as scope:
scope.cancel()
try:
await stream.aclose()
except get_cancelled_exc_class() as e:
exc = e
raise

assert exc is not None


@pytest.mark.skipif(
sys.platform == "win32", reason="UNIX sockets are not available on Windows"
)
class TestUNIXListener:
@pytest.fixture(
params=[
Expand Down
Loading