Uncaught-Exceptions / MCRcon

Use minecraft's new-fangled Rcon
Other
51 stars 12 forks source link

command on a broken rcon connection results in excessive CPU Load #6

Open Joshi425 opened 3 years ago

Joshi425 commented 3 years ago

Hi there,

when I try a command on a connection where the MC Server died or restarted, it results in python using an full CPU Core:

from mcrcon import MCRcon
import time
import os

rcon = MCRcon(os.environ['RCON_HOST'],os.environ['RCON_PASSWORD'],port=int(os.environ['RCON_PORT']))
rcon.connect()
time.sleep(10) # server stopped or died here
rcon.command("list")

the command never stops. the only way to recover from that is to restart the python script. Maybe a Timeout for Command or the connection would make sense. Related: https://github.com/Joshi425/minecraft-exporter/issues/11

unexceptable commented 3 years ago

Sorry, haven't played with anything Minecraft related in ages, and likely won't have a chance to fix this myself. But if you feel like opening a pull request which adds a timeout I will happily review/test it, then release a new version to pypi.

steveroch-rs commented 3 years ago

This is an issue I assume is caused by the socket being implemented as 'blocking'. If I have time, I'll look into it and fix it so that it uses a non-blocking socket. As for now I have forked the repo and will create a pull request as soon as I have it working.

unexceptable commented 3 years ago

So I've now merged and released a version that supports timeout. Which should mostly handle this... but @steveroch-rs if you want to still have a go at implementing non-blocking sockets, we can instead switch to that, but timeout should work for now.

unexceptable commented 3 years ago

@Joshi425 can you retest and see if the timeout fixes your issue?