[1/3] cooker/siggen: Support exit calls and use for hashserv client

Message ID 20220325092912.1350321-1-richard.purdie@linuxfoundation.org
State Accepted, archived
Commit 9ee3fb95330003878fbd64b3ce8897aad96fcd0f
Headers show
Series [1/3] cooker/siggen: Support exit calls and use for hashserv client | expand

Commit Message

Richard Purdie March 25, 2022, 9:29 a.m. UTC
We have shutdown functions within the async client code but the siggen
doesn't currently call them. We notice on python 3.10 (such as on fedora35)
that at exit, there is a stray asyncio process left behind. Usually this
doesn't cause problems but it could potentially be a cause of a hang.

For general cleanliness and completness, add in hooks to call the exit handler.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 lib/bb/cooker.py | 1 +
 lib/bb/siggen.py | 9 +++++++++
 2 files changed, 10 insertions(+)

Patch

diff --git a/lib/bb/cooker.py b/lib/bb/cooker.py
index f79dc2770d..c0a7a2fd79 100644
--- a/lib/bb/cooker.py
+++ b/lib/bb/cooker.py
@@ -1717,6 +1717,7 @@  class BBCooker:
     def post_serve(self):
         self.shutdown(force=True)
         prserv.serv.auto_shutdown()
+        bb.parse.siggen.exit()
         if self.hashserv:
             self.hashserv.process.terminate()
             self.hashserv.process.join()
diff --git a/lib/bb/siggen.py b/lib/bb/siggen.py
index 96e16a45f8..ff6b24ccda 100644
--- a/lib/bb/siggen.py
+++ b/lib/bb/siggen.py
@@ -156,6 +156,9 @@  class SignatureGenerator(object):
 
         return DataCacheProxy()
 
+    def exit(self):
+        return
+
 class SignatureGeneratorBasic(SignatureGenerator):
     """
     """
@@ -489,6 +492,12 @@  class SignatureGeneratorUniHashMixIn(object):
             self._client = hashserv.create_client(self.server)
         return self._client
 
+    def exit(self):
+        if getattr(self, '_client', None) is not None:
+            self._client.close()
+            self._client = None
+        return super().exit()
+
     def get_stampfile_hash(self, tid):
         if tid in self.taskhash:
             # If a unique hash is reported, use it as the stampfile hash. This