diff --git a/rcon/async_rcon.py b/rcon/async_rcon.py index ba5a02d..c2aa82c 100644 --- a/rcon/async_rcon.py +++ b/rcon/async_rcon.py @@ -10,6 +10,13 @@ from rcon.proto import Packet, Type __all__ = ['rcon'] +async def close(socket: IO) -> None + """Close socket asynchronously""" + + socket.close() + await socket.wait_closed() + + async def communicate(reader: IO, writer: IO, packet: Packet) -> Packet: """Asynchronous requests.""" @@ -32,10 +39,12 @@ async def rcon(command: str, *arguments: str, host: str, port: int, response = await Packet.aread(reader) if response.id == -1: + await close(writer) raise WrongPassword() request = Packet.make_command(command, *arguments, encoding=encoding) response = await communicate(reader, writer, request) + await close(writer) if response.id != request.id: raise RequestIdMismatch(request.id, response.id)