From 4f3230e36992122fd7b44a977fe77deac7f4898b Mon Sep 17 00:00:00 2001 From: Artur Shiriev Date: Tue, 27 Jan 2026 12:44:01 +0300 Subject: [PATCH] make ping to fail if broker is stopping --- .gitignore | 1 + packages/faststream-stomp/faststream_stomp/broker.py | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/.gitignore b/.gitignore index b40df4f2..88a76372 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ dist uv.lock .vscode __pycache__ +.idea diff --git a/packages/faststream-stomp/faststream_stomp/broker.py b/packages/faststream-stomp/faststream_stomp/broker.py index f78d1e6c..0d9e6bb2 100644 --- a/packages/faststream-stomp/faststream_stomp/broker.py +++ b/packages/faststream-stomp/faststream_stomp/broker.py @@ -135,6 +135,7 @@ def __init__( super().__init__(config=broker_config, specification=specification, routers=routers) self._attempted_to_connect = False + self._stopping = False async def _connect(self) -> stompman.Client: if self._attempted_to_connect: @@ -154,13 +155,19 @@ async def stop( exc_val: BaseException | None = None, exc_tb: types.TracebackType | None = None, ) -> None: + self._stopping = True for sub in self.subscribers: await sub.stop() if self._connection: await self._connection.__aexit__(exc_type, exc_val, exc_tb) + self._stopping = False self.running = False async def ping(self, timeout: float | None = None) -> bool: + # broker can be stuck in stopping state + if self._stopping: + return False + sleep_time = (timeout or 10) / 10 with anyio.move_on_after(timeout) as cancel_scope: if self._connection is None: