Skip to content

Commit

Permalink
fix(ota_proxy): fix a potential unbound in cache_streaming (#418)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bodong-Yang committed Dec 1, 2024
1 parent ec8b8d4 commit 4000d7d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/ota_proxy/cache_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4000d7d

Please sign in to comment.