Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix infinite recursion while shutting down TrackerSession #8339

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading