From e0b162e7edb3da3ba89cda73b5f2ceeaf8326a64 Mon Sep 17 00:00:00 2001 From: Bodong Yang <86948717+Bodong-Yang@users.noreply.github.com> Date: Mon, 11 Nov 2024 22:15:58 +0900 Subject: [PATCH] fix(ota_proxy): fix a potential unbound in cache_streaming (#418) --- src/ota_proxy/cache_streaming.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ota_proxy/cache_streaming.py b/src/ota_proxy/cache_streaming.py index 48237dc0d..17e14b02f 100644 --- a/src/ota_proxy/cache_streaming.py +++ b/src/ota_proxy/cache_streaming.py @@ -335,6 +335,7 @@ async def cache_streaming( Raises: CacheStreamingFailed if any exception happens during retrieving. """ + _cache_write_gen = None try: _cache_write_gen = await tracker.start_provider(cache_meta) _cache_writer_failed = False @@ -370,8 +371,9 @@ async def cache_streaming( finally: # force terminate the generator in all condition at exit, this # can ensure the generator being gced after cache_streaming exits. - with contextlib.suppress(StopAsyncIteration): - await _cache_write_gen.athrow(StopAsyncIteration) + if _cache_write_gen: + with contextlib.suppress(StopAsyncIteration): + await _cache_write_gen.athrow(StopAsyncIteration) # remove the refs fd, tracker = None, None # type: ignore