From 576e7c9cfc68a05bc9e6988883f8e96de55ffe2c Mon Sep 17 00:00:00 2001 From: KoNit-K <124019182+KoNit-K@users.noreply.github.com> Date: Tue, 15 Sep 2026 20:32:23 +0800 Subject: [PATCH] fix(state): tolerate Windows resource stubs --- hermes_state_readpool.py | 2 +- tests/hermes_cli/test_resource_limits.py | 7 +++++++ tests/hermes_state/test_session_db_read_conn_pool.py | 10 ++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/hermes_state_readpool.py b/hermes_state_readpool.py index 5b86cff7cc..50c55daee7 100644 --- a/hermes_state_readpool.py +++ b/hermes_state_readpool.py @@ -101,7 +101,7 @@ def _fd_soft_limit() -> Optional[int]: return None try: soft, _hard = resource.getrlimit(resource.RLIMIT_NOFILE) - except (OSError, ValueError): + except (AttributeError, OSError, ValueError): return None if soft in (resource.RLIM_INFINITY, -1): return None diff --git a/tests/hermes_cli/test_resource_limits.py b/tests/hermes_cli/test_resource_limits.py index 22018f30a7..a4dd998cf4 100644 --- a/tests/hermes_cli/test_resource_limits.py +++ b/tests/hermes_cli/test_resource_limits.py @@ -100,6 +100,13 @@ def test_unsupported_platform_is_a_safe_noop(monkeypatch): assert resource_limits.apply_nofile_soft_limit({}) is False +def test_windows_resource_stub_without_rlimit_attributes_is_a_safe_noop(monkeypatch): + """Windows can import ``resource`` even when its POSIX API is absent.""" + monkeypatch.setattr(resource_limits, "_resource", object()) + + assert resource_limits.apply_nofile_soft_limit({}) is False + + def test_fresh_process_import_without_posix_resource_is_a_safe_noop(): code = textwrap.dedent( """ diff --git a/tests/hermes_state/test_session_db_read_conn_pool.py b/tests/hermes_state/test_session_db_read_conn_pool.py index 696d00caae..3d8f0352b4 100644 --- a/tests/hermes_state/test_session_db_read_conn_pool.py +++ b/tests/hermes_state/test_session_db_read_conn_pool.py @@ -627,6 +627,16 @@ def test_fd_headroom_guard_fails_open_where_it_cannot_measure(monkeypatch): assert readpool._fd_headroom_ok() is False +def test_fd_soft_limit_ignores_windows_resource_stub(monkeypatch): + """A Windows resource stub has no POSIX RLIMIT attributes.""" + import sys + from types import SimpleNamespace + + monkeypatch.setitem(sys.modules, "resource", SimpleNamespace()) + + assert hermes_state_readpool._fd_soft_limit() is None + + @pytest.mark.requires_wal def test_duplicate_handles_on_one_path_are_reported(db, caplog): """Writer connections cannot be capped, so duplicates must be visible."""