From c7285455d522bad266e4efbdd378eacfcdc2b164 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Thu, 21 May 2026 00:02:57 +0000 Subject: [PATCH] fix(rubrik): cancel periodic flush task on aclose The aclose() method closed both HTTP clients but did not cancel the periodic flush task. After close, the task would wake up every flush_interval seconds and try to POST via the now-closed async_httpx_client, generating recurring errors. Cancel the task and await its termination before closing the clients. Co-authored-by: Yassin Kortam --- litellm/integrations/rubrik.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/litellm/integrations/rubrik.py b/litellm/integrations/rubrik.py index 193c6709867..601a1376cb3 100644 --- a/litellm/integrations/rubrik.py +++ b/litellm/integrations/rubrik.py @@ -143,6 +143,15 @@ class RubrikLogger(CustomGuardrail, CustomBatchLogger): async def aclose(self): """Close the dedicated HTTP clients used by this logger.""" + # Cancel the periodic flush task before closing the HTTP clients so + # the loop doesn't wake up and try to POST via a closed client. + if self._flush_task is not None and not self._flush_task.done(): + self._flush_task.cancel() + try: + await self._flush_task + except (asyncio.CancelledError, Exception): + pass + self._flush_task = None await self.tool_blocking_client.close() await self.async_httpx_client.close()