From f9ce373b70e93d63655c934127340b8ce2281346 Mon Sep 17 00:00:00 2001 From: forhim007 Date: Fri, 8 May 2026 01:12:44 +0800 Subject: [PATCH] fix: publisher not cleaned up on error in load_document (#871) Wrap publisher send in try/finally so that pub.stop() is always called, even if pub.send() raises an exception. This matches the existing pattern used in emit_document_provenance (lines 345-361). Also expanded the FIXME comment on the asyncio.sleep(1) to clarify what it may be compensating for and that further investigation is needed. --- trustgraph-flow/trustgraph/librarian/service.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/trustgraph-flow/trustgraph/librarian/service.py b/trustgraph-flow/trustgraph/librarian/service.py index c24a5fe8..754d1727 100755 --- a/trustgraph-flow/trustgraph/librarian/service.py +++ b/trustgraph-flow/trustgraph/librarian/service.py @@ -418,14 +418,18 @@ class Processor(AsyncProcessor): self.pubsub, q, schema=schema ) - await pub.start() + try: + await pub.start() - # FIXME: Time wait kludge? - await asyncio.sleep(1) + # FIXME: Time wait kludge? + # This sleep may be compensating for async startup timing in the + # underlying pubsub producer. Further investigation is needed to + # determine if it can be removed. + await asyncio.sleep(1) - await pub.send(None, doc) - - await pub.stop() + await pub.send(None, doc) + finally: + await pub.stop() logger.debug("Document submitted")