From ec56f69158adf75862a1429523902f731c01ee8d Mon Sep 17 00:00:00 2001 From: forhim007 Date: Thu, 7 May 2026 23:24:11 +0800 Subject: [PATCH] fix: ensure publisher is cleaned up on error in submit_document If pub.send() raises an exception, pub.stop() was never called, leaking the publisher and its underlying connection. Wrap the pub.start()/pub.send() calls in try/finally so pub.stop() is always called, matching the existing pattern at lines 345-361. Fixes #871 --- trustgraph-flow/trustgraph/librarian/service.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/trustgraph-flow/trustgraph/librarian/service.py b/trustgraph-flow/trustgraph/librarian/service.py index c24a5fe8..b41f177e 100755 --- a/trustgraph-flow/trustgraph/librarian/service.py +++ b/trustgraph-flow/trustgraph/librarian/service.py @@ -418,14 +418,15 @@ 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? + 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")