Skip to content

Commit

Permalink
fix: slight memory leak in Events loader (#853)
Browse files Browse the repository at this point in the history
* fix: slight memory leak in Events loader

* chore: `black .`

* chore: refactor

* chore: `black .`

* Update common.py

* chore: `black .`

* Update common.py

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
BobTheBuidler and github-actions[bot] authored Dec 15, 2024
1 parent d5b6130 commit 5485e59
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
24 changes: 15 additions & 9 deletions y/_db/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,16 +603,20 @@ async def _set_lock(self, block: int) -> None:
def _insert_chunk(
self, objs: List[T], from_block: int, done_thru: int, debug_logs: bool
) -> None:
if (
(prev_task := self._db_task)
and prev_task.done()
and (e := prev_task.exception())
):
raise e
depth = prev_task._depth + 1 if prev_task else 0

if prev_task := self._db_task:
if prev_task.done():
if e := prev_task.exception():
raise e
prev_task = None

depth = self._depth
self._depth += 1

insert_coro = self.__insert_chunk(
objs, from_block, done_thru, prev_task, depth, debug_logs
)

if debug_logs:
logger._log(
logging.DEBUG,
Expand All @@ -627,7 +631,6 @@ def _insert_chunk(
task = asyncio.create_task(insert_coro)

task._depth = depth
task._prev_task = prev_task
self._db_task = task

def _ensure_task(self) -> None:
Expand All @@ -642,7 +645,6 @@ def _ensure_task(self) -> None:
if self._task.done() and (e := self._task.exception()):
raise e.with_traceback(e.__traceback__)

@stuck_coro_debugger
async def __insert_chunk(
self,
objs: List[T],
Expand All @@ -654,8 +656,12 @@ async def __insert_chunk(
) -> None:
if prev_chunk_task:
await prev_chunk_task
del prev_chunk_task

if objs:
await self.bulk_insert(objs)
del objs

await self.executor.run(self.cache.set_metadata, from_block, done_thru)
if debug_logs:
logger._log(
Expand Down
4 changes: 3 additions & 1 deletion y/contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,9 @@ def _resolve_proxy(address) -> Tuple[str, List]:
return name, abi


@alru_cache(ttl=300) # we loosely cache this so we don't have to repeatedly fetch abis for commonly used proxy implementations
@alru_cache(
ttl=300
) # we loosely cache this so we don't have to repeatedly fetch abis for commonly used proxy implementations
async def _extract_abi_data_async(address: Address):
"""
Extract ABI data for a contract from the blockchain explorer.
Expand Down

0 comments on commit 5485e59

Please sign in to comment.