Bugfix: Doesn't get out of "Reader or writer missing" state.
authorBenjamin Braatz <bb@bbraatz.eu>
Mon, 26 May 2025 01:33:43 +0000 (03:33 +0200)
committerBenjamin Braatz <bb@bbraatz.eu>
Mon, 26 May 2025 12:00:05 +0000 (14:00 +0200)
controlpi_plugins/graph_connection.py

index 8a9d305b85a68d70732dc254ac299df9d489a604..1d1358eb3aa8d7fd6eb500b90f797ceaeda08bce 100644 (file)
@@ -112,4 +112,25 @@ class GraphConnection:
                 # Return result:
                 return response['result']
             else:
-                raise Exception("Reader or writer missing.")
+                if writer is not None:
+                    writer.close()
+                    self.connection.closed += 1
+                # Open connection:
+                (r, w) = await asyncio.open_connection(self.hostname,
+                                                       self.port,
+                                                       ssl=self.ssl)
+                self.connection.opened += 1
+                # Read banner:
+                size_bytes = await r.readexactly(4)
+                size_int = struct.unpack('<i', size_bytes)[0]
+                message = await r.readexactly(size_int)
+                # Set reader and writer in data:
+                self.connection.reader = r
+                self.connection.writer = w
+                raise Exception("Reader or writer missing. Reopened.\n"
+                                "Currently open contexts:"
+                                f" {self.connection.contexts}\n"
+                                "Connections opened since start: "
+                                f" {self.connection.opened}\n"
+                                "Connections closed since start: "
+                                f" {self.connection.closed}")