Skip to content

Commit e5dd276

Browse files
authored
Fix infinite recursion while shutting down TrackerSession (#8339)
2 parents 1ed1139 + 33bdaa1 commit e5dd276

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/tribler/core/torrent_checker/torrentchecker_session.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
import struct
77
import time
88
from abc import ABCMeta, abstractmethod
9-
from asyncio import DatagramProtocol, Future, TimeoutError, ensure_future, get_event_loop
9+
from asyncio import DatagramProtocol, Future, Task, ensure_future, get_event_loop
10+
from asyncio import TimeoutError as AsyncTimeoutError
1011
from typing import TYPE_CHECKING, Any, List, NoReturn, cast
1112

1213
import async_timeout
@@ -59,6 +60,7 @@ def __init__(self, tracker_type: str, tracker_url: str, tracker_address: tuple[s
5960
self.timeout = timeout
6061
self.infohash_list: list[bytes] = []
6162
self.last_contact = 0
63+
self.cleanup_task: Task | None = None
6264

6365
# some flags
6466
self.is_initiated = False # you cannot add requests to a session if it has been initiated
@@ -102,8 +104,8 @@ def failed(self, msg: str | None = None) -> NoReturn:
102104
103105
:raises ValueError: always.
104106
"""
105-
if not self.is_failed:
106-
self.register_anonymous_task("Cleanup", self.cleanup)
107+
if not self.is_failed and not self.cleanup_task:
108+
self.cleanup_task = ensure_future(self.cleanup())
107109
self.is_failed = True
108110
result_msg = f"{self.tracker_type} tracker failed for url {self.tracker_url}"
109111
if msg:
@@ -363,7 +365,7 @@ async def connect_to_tracker(self) -> TrackerResponse:
363365
self.ip_address = infos[0][-1][0]
364366
await self.connect()
365367
return await self.scrape()
366-
except TimeoutError:
368+
except AsyncTimeoutError:
367369
self.failed(msg="request timed out")
368370
except socket.gaierror as e:
369371
self.failed(msg=str(e))

0 commit comments

Comments
 (0)