perf(middleware): await background task cancellation on timeout

This commit is contained in:
Ishaan Gupta 2026-03-18 22:35:10 +05:30
parent c534008001
commit e97fdc338c

View file

@ -554,9 +554,12 @@ class SupermemoryOpenAIWrapper:
f"Background tasks did not complete within {timeout}s timeout"
)
# Cancel remaining tasks
for task in self._background_tasks:
if not task.done():
task.cancel()
tasks_to_cancel = [task for task in self._background_tasks if not task.done()]
for task in tasks_to_cancel:
task.cancel()
if tasks_to_cancel:
await asyncio.gather(*tasks_to_cancel, return_exceptions=True)
raise
def cancel_background_tasks(self) -> None: