diff options
author | Paul Barker <pbarker@konsulko.com> | 2021-06-07 16:03:33 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2021-07-27 09:27:31 +0100 |
commit | b31f1853d7fcb8b8f8885ca513a0021a5d0301e6 (patch) | |
tree | 3ff30c08cfe313e50a05cf1db85994be4973bad3 /lib/bb/asyncrpc/client.py | |
parent | bd8f8d7b055da15cd7bdd0b383061852a0f54cb7 (diff) | |
download | bitbake-contrib-b31f1853d7fcb8b8f8885ca513a0021a5d0301e6.tar.gz |
asyncrpc: Set timeout when waiting for reply from server
Signed-off-by: Paul Barker <pbarker@konsulko.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'lib/bb/asyncrpc/client.py')
-rw-r--r-- | lib/bb/asyncrpc/client.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/bb/asyncrpc/client.py b/lib/bb/asyncrpc/client.py index d917ab597..3eb4fdde8 100644 --- a/lib/bb/asyncrpc/client.py +++ b/lib/bb/asyncrpc/client.py @@ -11,13 +11,14 @@ from . import chunkify, DEFAULT_MAX_CHUNK class AsyncClient(object): - def __init__(self, proto_name, proto_version, logger): + def __init__(self, proto_name, proto_version, logger, timeout=30): self.reader = None self.writer = None self.max_chunk = DEFAULT_MAX_CHUNK self.proto_name = proto_name self.proto_version = proto_version self.logger = logger + self.timeout = timeout async def connect_tcp(self, address, port): async def connect_sock(): @@ -70,7 +71,11 @@ class AsyncClient(object): async def send_message(self, msg): async def get_line(): - line = await self.reader.readline() + try: + line = await asyncio.wait_for(self.reader.readline(), self.timeout) + except asyncio.TimeoutError: + raise ConnectionError("Timed out waiting for server") + if not line: raise ConnectionError("Connection closed") |