Skip to content

Commit 01b220e

Browse files
add try/finally to ensure we exit on close error
1 parent 18816bd commit 01b220e

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

faststream/broker/subscriber/usecase.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,13 @@ async def consume(self, msg: MsgType) -> Any:
311311

312312
except SystemExit:
313313
# Stop handler at `exit()` call
314-
await self.close()
315-
316-
if app := context.get("app"):
317-
app.exit()
314+
try:
315+
await self.close()
316+
finally:
317+
# Ensure that app.exit() is called on a shutdown request
318+
# even if the consumer close operation threw an error.
319+
if app := context.get("app"):
320+
app.exit()
318321

319322
except Exception: # nosec B110
320323
# All other exceptions were logged by CriticalLogMiddleware

0 commit comments

Comments
 (0)