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()