From 61c99abcf1bd61b9278fa7cb32e037653b857d20 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Tue, 8 Mar 2022 17:32:35 -0300 Subject: [PATCH] avoid readding the same hash when tracker is busy with too many files --- lbry/torrent/tracker.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lbry/torrent/tracker.py b/lbry/torrent/tracker.py index e02659893..5d3956419 100644 --- a/lbry/torrent/tracker.py +++ b/lbry/torrent/tracker.py @@ -131,6 +131,7 @@ class TrackerClient: self.announce_port = announce_port self.servers = servers self.results = {} # we can't probe the server before the interval, so we keep the result here until it expires + self.tasks = {} async def start(self): self.transport, _ = await asyncio.get_running_loop().create_datagram_endpoint( @@ -145,7 +146,10 @@ class TrackerClient: self.EVENT_CONTROLLER.close() def on_hash(self, info_hash): - asyncio.ensure_future(self.get_peer_list(info_hash)) + if info_hash not in self.tasks: + fut = asyncio.ensure_future(self.get_peer_list(info_hash)) + fut.add_done_callback(lambda *_: self.tasks.pop(info_hash, None)) + self.tasks[info_hash] = fut async def get_peer_list(self, info_hash, stopped=False): found = []