From c1f056299588c9af2780c5c10d0db38d10907165 Mon Sep 17 00:00:00 2001 From: Krzysztof kuhy Rudnicki Date: Wed, 11 Nov 2026 14:56:00 +0100 Subject: [PATCH] Research tick survives pacman timeouts Under load pacman -Qi / iptables exceed their 10 s timeouts inside the research-window pass; the uncaught TimeoutExpired crashed the daemon (systemd restart loop). The pass now logs and retries next tick. Co-Authored-By: Claude Opus 5.5 --- steam_backlog_enforcer/_research_tick.py | 8 +++++- .../tests/test_research_tick.py | 25 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/steam_backlog_enforcer/_research_tick.py b/steam_backlog_enforcer/_research_tick.py index d124746..0f054b0 100644 --- a/steam_backlog_enforcer/_research_tick.py +++ b/steam_backlog_enforcer/_research_tick.py @@ -19,6 +19,7 @@ from __future__ import annotations from dataclasses import replace import logging +import subprocess from typing import TYPE_CHECKING from leisure_watch.procscan import LAUNCHER_PROCESS_NAMES, kill_target_names @@ -100,7 +101,12 @@ def total_block_pass(config: Config) -> None: at = window.now() record = window.live_record(at) if record is not None and record.is_open(at): - _research_pass(record) + # A loaded machine can push pacman/iptables past their timeouts; that + # costs this tick (the next one retries), never the daemon. + try: + _research_pass(record) + except OSError, subprocess.SubprocessError: + logger.exception("Research window pass failed; retrying next tick") return if record is not None and not record.closed and at >= record.until: record = _latch_closed(record) diff --git a/steam_backlog_enforcer/tests/test_research_tick.py b/steam_backlog_enforcer/tests/test_research_tick.py index cca3ba2..d7ba01b 100644 --- a/steam_backlog_enforcer/tests/test_research_tick.py +++ b/steam_backlog_enforcer/tests/test_research_tick.py @@ -2,6 +2,10 @@ from __future__ import annotations +import subprocess + +import pytest + from steam_backlog_enforcer import _research_record as store from steam_backlog_enforcer import _research_window as window from steam_backlog_enforcer import config as cfg @@ -106,3 +110,24 @@ class TestOpenWindow: run_pass() assert cfg.STATE_FILE.read_bytes() == before assert tm.enforce.call_args.args[0] == {window.LIBRARIAN_APP_ID} + + +class TestSlowSystem: + """A command that times out costs one tick, never the daemon.""" + + @pytest.mark.parametrize( + "error", + [subprocess.TimeoutExpired(["pacman", "-Qi", "steam"], 10), OSError("busy")], + ) + def test_failed_reconcile_is_retried_next_tick( + self, tm: Mocks, error: Exception + ) -> None: + """Test that a timed-out pacman/iptables call does not crash the loop.""" + tm.reconcile.side_effect = error + window.write_record(make_record()) + run_pass() + tm.block_tick.assert_not_called() + tm.enforce.assert_not_called() + tm.reconcile.side_effect = None + run_pass() + tm.enforce.assert_called_once()