Skip to content

Commit

Permalink
Ensure bot doesn't indefinitely hang on an exception in on_ready (#6202)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackenmen authored Jul 19, 2023
1 parent 48cfde7 commit bad23a4
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions redbot/core/_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from packaging.requirements import Requirement
from redbot.core import data_manager

from redbot.core.bot import ExitCodes
from redbot.core.commands import RedHelpFormatter, HelpSettings
from redbot.core.i18n import (
Translator,
Expand Down Expand Up @@ -140,6 +141,13 @@ async def on_connect():

@bot.event
async def on_ready():
try:
await _on_ready()
except Exception as exc:
log.critical("The bot failed to get ready!", exc_info=exc)
sys.exit(ExitCodes.CRITICAL)

async def _on_ready():
if bot._uptime is not None:
return

Expand Down Expand Up @@ -170,13 +178,12 @@ async def on_ready():

outdated_red_message = ""
rich_outdated_message = ""
with contextlib.suppress(aiohttp.ClientError, asyncio.TimeoutError):
pypi_version, py_version_req = await fetch_latest_red_version_info()
outdated = pypi_version and pypi_version > red_version_info
if outdated:
outdated_red_message, rich_outdated_message = get_outdated_red_messages(
pypi_version, py_version_req
)
pypi_version, py_version_req = await fetch_latest_red_version_info()
outdated = pypi_version and pypi_version > red_version_info
if outdated:
outdated_red_message, rich_outdated_message = get_outdated_red_messages(
pypi_version, py_version_req
)

rich_console = rich.get_console()
rich_console.print(INTRO, style="red", markup=False, highlight=False)
Expand Down

0 comments on commit bad23a4

Please sign in to comment.