Skip to content

Commit 33b5482

Browse files
committed
fix: memory leak on binance in combination with aiohttp>3.10
apparently, returning big data through run_until_complete can cause this (or closes freqtrade#11317
1 parent 43fea43 commit 33b5482

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

freqtrade/exchange/exchange.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -637,9 +637,9 @@ def ws_connection_reset(self):
637637
if self._exchange_ws:
638638
self._exchange_ws.reset_connections()
639639

640-
async def _api_reload_markets(self, reload: bool = False) -> dict[str, Any]:
640+
async def _api_reload_markets(self, reload: bool = False) -> None:
641641
try:
642-
return await self._api_async.load_markets(reload=reload, params={})
642+
await self._api_async.load_markets(reload=reload, params={})
643643
except ccxt.DDoSProtection as e:
644644
raise DDosProtection(e) from e
645645
except (ccxt.OperationFailed, ccxt.ExchangeError) as e:
@@ -649,14 +649,14 @@ async def _api_reload_markets(self, reload: bool = False) -> dict[str, Any]:
649649
except ccxt.BaseError as e:
650650
raise TemporaryError(e) from e
651651

652-
def _load_async_markets(self, reload: bool = False) -> dict[str, Any]:
652+
def _load_async_markets(self, reload: bool = False) -> None:
653653
try:
654654
with self._loop_lock:
655655
markets = self.loop.run_until_complete(self._api_reload_markets(reload=reload))
656656

657657
if isinstance(markets, Exception):
658658
raise markets
659-
return markets
659+
return None
660660
except asyncio.TimeoutError as e:
661661
logger.warning("Could not load markets. Reason: %s", e)
662662
raise TemporaryError from e
@@ -679,7 +679,8 @@ def reload_markets(self, force: bool = False, *, load_leverage_tiers: bool = Tru
679679
# on initial load, we retry 3 times to ensure we get the markets
680680
retries: int = 3 if force else 0
681681
# Reload async markets, then assign them to sync api
682-
self._markets = retrier(self._load_async_markets, retries=retries)(reload=True)
682+
retrier(self._load_async_markets, retries=retries)(reload=True)
683+
self._markets = self._api_async.markets
683684
self._api.set_markets(self._api_async.markets, self._api_async.currencies)
684685
# Assign options array, as it contains some temporary information from the exchange.
685686
self._api.options = self._api_async.options

0 commit comments

Comments
 (0)