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

[Audio] add a separate timeout for lavalink download #6461

Open
wants to merge 1 commit into
base: V3/develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion redbot/cogs/audio/core/tasks/lavalink.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ async def lavalink_attempt_connect(self, timeout: int = 50, manual: bool = False
password = configs["yaml"]["lavalink"]["server"]["password"]
secured = False
# Make this timeout customizable for lower powered machines?
self.managed_node_controller = ServerManager(self.config, timeout=60, cog=self)
self.managed_node_controller = ServerManager(
self.config, timeout=60, download_timeout=60 * 3, cog=self
)
try:
await self.managed_node_controller.start(java_exec)
# timeout is the same as ServerManager.timeout -
Expand Down
22 changes: 20 additions & 2 deletions redbot/cogs/audio/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,21 @@ class ServerManager:
_buildtime: ClassVar[Optional[str]] = None
_java_exc: ClassVar[str] = "java"

def __init__(self, config: Config, cog: "Audio", timeout: Optional[int] = None) -> None:
def __init__(
self,
config: Config,
cog: "Audio",
timeout: Optional[int] = None,
download_timeout: Optional[int] = None,
) -> None:
self.ready: asyncio.Event = asyncio.Event()
self.downloaded: asyncio.Event = asyncio.Event()
self._config = config
self._proc: Optional[asyncio.subprocess.Process] = None # pylint:disable=no-member
self._shutdown: bool = False
self.start_monitor_task = None
self.timeout = timeout
self.download_timeout = download_timeout
self.cog = cog
self._args = []
self._pipe_task = None
Expand Down Expand Up @@ -414,6 +422,7 @@ async def _download_jar(self) -> None:

log.info("Successfully downloaded Lavalink.jar (%s bytes written)", format(nbytes, ","))
await self._is_up_to_date()
self.downloaded.set()

async def _is_up_to_date(self):
if self._up_to_date is True:
Expand Down Expand Up @@ -470,13 +479,15 @@ async def _is_up_to_date(self):
async def maybe_download_jar(self):
if not self.lavalink_jar_file.exists():
log.info("Triggering first-time download of Lavalink...")
self.downloaded.clear()
await self._download_jar()
return

try:
up_to_date = await self._is_up_to_date()
except ValueError as exc:
log.warning("Failed to get Lavalink version: %s\nTriggering update...", exc)
self.downloaded.clear()
await self._download_jar()
return

Expand All @@ -486,9 +497,16 @@ async def maybe_download_jar(self):
self._lavalink_version,
managed_node.JAR_VERSION,
)
self.downloaded.clear()
await self._download_jar()
else:
self.downloaded.set()

async def wait_until_ready(self, timeout: Optional[float] = None):
async def wait_until_ready(
self, timeout: Optional[float] = None, download_timeout: Optional[float] = None
):
download_timeout = download_timeout or self.download_timeout
await asyncio.wait_for(self.downloaded.wait(), timeout=download_timeout)
await asyncio.wait_for(self.ready.wait(), timeout=timeout or self.timeout)

async def start_monitor(self, java_path: str):
Expand Down
Loading