Skip to content

Commit

Permalink
Fix infinite recursion while shutting down TrackerSession (#8339)
Browse files Browse the repository at this point in the history
  • Loading branch information
egbertbouman authored Dec 13, 2024
2 parents 1ed1139 + 33bdaa1 commit e5dd276
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/tribler/core/torrent_checker/torrentchecker_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import struct
import time
from abc import ABCMeta, abstractmethod
from asyncio import DatagramProtocol, Future, TimeoutError, ensure_future, get_event_loop
from asyncio import DatagramProtocol, Future, Task, ensure_future, get_event_loop
from asyncio import TimeoutError as AsyncTimeoutError
from typing import TYPE_CHECKING, Any, List, NoReturn, cast

import async_timeout
Expand Down Expand Up @@ -59,6 +60,7 @@ def __init__(self, tracker_type: str, tracker_url: str, tracker_address: tuple[s
self.timeout = timeout
self.infohash_list: list[bytes] = []
self.last_contact = 0
self.cleanup_task: Task | None = None

# some flags
self.is_initiated = False # you cannot add requests to a session if it has been initiated
Expand Down Expand Up @@ -102,8 +104,8 @@ def failed(self, msg: str | None = None) -> NoReturn:
:raises ValueError: always.
"""
if not self.is_failed:
self.register_anonymous_task("Cleanup", self.cleanup)
if not self.is_failed and not self.cleanup_task:
self.cleanup_task = ensure_future(self.cleanup())
self.is_failed = True
result_msg = f"{self.tracker_type} tracker failed for url {self.tracker_url}"
if msg:
Expand Down Expand Up @@ -363,7 +365,7 @@ async def connect_to_tracker(self) -> TrackerResponse:
self.ip_address = infos[0][-1][0]
await self.connect()
return await self.scrape()
except TimeoutError:
except AsyncTimeoutError:
self.failed(msg="request timed out")
except socket.gaierror as e:
self.failed(msg=str(e))
Expand Down

0 comments on commit e5dd276

Please sign in to comment.