Fail safe, not dead: bound the HID cancel wait, isolate sensor failures, keep the fan worker alive

- hid.py: after a timed-out HID operation, wait at most 1 s for the driver to
  finish the cancelled IRP; if it does not, mark the channel broken so the
  caller's reconnect path closes it instead of blocking forever on a wedged
  device. Keep abandoned OVERLAPPED/buffer references alive until close so a
  late IRP completion cannot write into reused memory. Check CreateEventW.
- telemetry/service.py: read each source (CPU, GPU, system power, GPU memory)
  independently; a failing source now costs only its own readings instead of
  the whole sample, logged at most once a minute per source.
- sensors.py: the Commander PRO iCUE ownership check runs inside a guard; if
  ownership cannot be established the device is released rather than risking
  swapped replies (and the failure no longer escapes into the sample).
- cooling/control.py: an unexpected exception no longer ends fan control for
  the life of the process; fail safe, log at most once a minute, retry with a
  fresh sensor object after 5 s. failsafe() no longer raises, and control
  errors back off 5 s instead of re-opening the device every second.
This commit is contained in:
paul committed 2026-12-05 16:47:16 +13:00
1 parent 7356809c0a
commit d637d46777
5 files changed
+102 -26

No files matched your search

+15 -9
View File
@@ -691,16 +691,22 @@ class CommanderPro:
now = time.monotonic()
if now >= self._next_check:
self._next_check = now + self.RECHECK
if self._corsair_software_running():
self.close()
self._say("iCUE is running, leaving the device to it")
elif self.ch is None:
try:
self._open()
self._say(f"reading {len(self.ports)} fans (ports {', '.join(str(p + 1) for p in self.ports)})")
except Exception as e:
try:
if self._corsair_software_running():
self.close()
self._say(f"unavailable ({e})")
self._say("iCUE is running, leaving the device to it")
elif self.ch is None:
try:
self._open()
self._say(f"reading {len(self.ports)} fans (ports {', '.join(str(p + 1) for p in self.ports)})")
except Exception as e:
self.close()
self._say(f"unavailable ({e})")
except Exception as e:
# Ownership cannot be established (e.g. process enumeration failed): give the
# device up rather than risk swapped replies, and retry on the next check.
self.close()
self._say(f"ownership check failed ({e}); device released, retrying in {self.RECHECK:.0f} s")
if self.ch is not None:
try:
for p in self.ports:
+17 -3
View File
@@ -50,15 +50,29 @@ class Telemetry:
self._history: collections.deque[tuple] = collections.deque(maxlen=int(HISTORY_SECONDS / interval))
self._listeners: list[Callable[[Sample], None]] = []
self._seq = 0
self._last_failure: dict[str, float] = {}
def subscribe(self, listener: Callable[[Sample], None]) -> None:
self._listeners.append(listener)
def read(self) -> Sample:
c, g = self.cpu.read(), self.gpu.read()
p = self.system.read(c, g)
"""Read every source independently: one failing source costs only its own readings."""
c = self._source("CPU sensors", self.cpu.read, Readings())
g = self._source("GPU sensors", self.gpu.read, Readings())
p = self._source("system power", self.system.read, PowerReadings(), c, g)
vram = self._source("GPU memory", self.gpu.memory, None)
self._seq += 1
return Sample(self._seq, time.time(), c, g, p, self.gpu.memory())
return Sample(self._seq, time.time(), c, g, p, vram)
def _source(self, name: str, read: Callable, fallback, *args):
try:
return read(*args)
except Exception as e:
# The loop retries every second, so log each failing source at most once a minute.
if time.monotonic() - self._last_failure.get(name, -1e9) >= 60:
self._last_failure[name] = time.monotonic()
log.warning("%s read failed; continuing without it: %s", name, e, exc_info=True)
return fallback
def run(self, stop: threading.Event) -> None:
while not stop.is_set():