From: Benjamin Braatz Date: Wed, 21 May 2025 12:30:41 +0000 (+0200) Subject: Protect _call() with lock to ensure only one call at a time. X-Git-Url: http://git.graph-it.com/?a=commitdiff_plain;h=ebed85b0baa5840befff1b7c3939ab9b190e44d2;p=graphit%2Fcontrolpi-graph.git Protect _call() with lock to ensure only one call at a time. --- diff --git a/controlpi_plugins/graph.py b/controlpi_plugins/graph.py index 025dbd1..23572a6 100644 --- a/controlpi_plugins/graph.py +++ b/controlpi_plugins/graph.py @@ -35,6 +35,7 @@ class Graph(BasePlugin): self._ssl_ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2) self._ssl_ctx.load_cert_chain(self.conf['crt']) self._open_connections = 0 + self._call_lock = asyncio.Lock() self._messages: List[Message] = [] self.bus.register(self.name, 'Graph', [], @@ -86,47 +87,50 @@ class Graph(BasePlugin): (reader, writer) = await asyncio.open_connection(self._host, self._port, ssl=self._ssl_ctx) - self._reader = reader - self._writer = writer - if self._writer and self._reader: + if writer and reader: # Read banner: - size_bytes = await self._reader.readexactly(4) - size_int = struct.unpack(' Any: if self._writer and self._reader: - # Build request: - self._call_id += 1 - request = {'jsonrpc': '2.0', 'method': method, - 'params': params, 'id': self._call_id} - message = msgpack.packb(request) - size_bytes = struct.pack(' None: if self._open_connections > 0: - self.open_connections -= 1 + self._open_connections -= 1 if self._open_connections == 0: if self._writer: # Close connection: