Race Condition in RCON Connection #5

Open
opened 2026-02-02 15:10:11 -05:00 by jared · 0 comments
Owner

with MCRcon(MINECRAFT_RCON_HOST, MINECRAFT_RCON_PASSWORD) as mcr:
response = mcr.command(f"whitelist add {minecraft_username}")

Issue: No timeout, no retry logic, blocking call in async context.

Fix:

import asyncio
from functools import partial

async def rcon_command(host: str, password: str, command: str, timeout: float = 5.0):
"""Execute RCON command with timeout"""
try:
loop = asyncio.get_event_loop()
func = partial(execute_rcon, host, password, command)
return await asyncio.wait_for(loop.run_in_executor(None, func), timeout=timeout)
except asyncio.TimeoutError:
raise Exception("RCON timeout - server may be offline")
except Exception as e:
raise Exception(f"RCON error: {str(e)}")

def execute_rcon(host: str, password: str, command: str):
with MCRcon(host, password, timeout=3) as mcr:
return mcr.command(command)

with MCRcon(MINECRAFT_RCON_HOST, MINECRAFT_RCON_PASSWORD) as mcr: response = mcr.command(f"whitelist add {minecraft_username}") Issue: No timeout, no retry logic, blocking call in async context. Fix: import asyncio from functools import partial async def rcon_command(host: str, password: str, command: str, timeout: float = 5.0): """Execute RCON command with timeout""" try: loop = asyncio.get_event_loop() func = partial(execute_rcon, host, password, command) return await asyncio.wait_for(loop.run_in_executor(None, func), timeout=timeout) except asyncio.TimeoutError: raise Exception("RCON timeout - server may be offline") except Exception as e: raise Exception(f"RCON error: {str(e)}") def execute_rcon(host: str, password: str, command: str): with MCRcon(host, password, timeout=3) as mcr: return mcr.command(command)
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: LotusGuild/discordBot#5