From 9da71e1b59334cb146b218454c034f363b6dc168 Mon Sep 17 00:00:00 2001 From: Debby Mendez <118911638+debbyglance@users.noreply.github.com> Date: Mon, 28 Oct 2024 09:56:13 -0400 Subject: [PATCH] Fix issue #624 A cancelled future in the flush_queue can cause the flusher task to fail with InvalidStateError, attempting to set the result on a "done" future. --- nats/aio/client.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/nats/aio/client.py b/nats/aio/client.py index 81e65f50..e5ca2834 100644 --- a/nats/aio/client.py +++ b/nats/aio/client.py @@ -2084,7 +2084,9 @@ async def _flusher(self) -> None: # RuntimeError in case the event loop is closed break finally: - future.set_result(None) + # future might have been cancelled. See issue #624 + if not future.done(): + future.set_result(None) async def _ping_interval(self) -> None: while True: