Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions python/lean_pool/build_time_limits.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ def _process_identity(pid: int) -> tuple[int, int, int] | None:
"""Read kernel start ticks, current parent and group for a candidate PID."""
try:
stat = Path(f"/proc/{pid}/stat").read_text()
except FileNotFoundError:
except (FileNotFoundError, ProcessLookupError):
# ProcessLookupError: the process was reaped between open and read.
return None
fields = stat.rsplit(")", 1)[1].split()
return int(fields[19]), int(fields[1]), int(fields[2])
Expand Down Expand Up @@ -322,7 +323,7 @@ def _process_state(pid: int) -> str | None:
"""Read the leader state without reaping its PID or releasing its group ID."""
try:
stat = Path(f"/proc/{pid}/stat").read_text()
except FileNotFoundError:
except (FileNotFoundError, ProcessLookupError):
return None
return stat.rsplit(")", 1)[1].split()[0]

Expand Down
11 changes: 11 additions & 0 deletions python/tests/test_build_time_limits.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,3 +784,14 @@ def test_workflow_rebuilds_changed_modules_after_all_compiled_restores() -> None
assert restore_index < index, (name, step.get("name"))
if "-m lean_pool.queue_build" in run and "--receipts" in run:
assert restore_index > index


@pytest.mark.parametrize("reader", [limits._process_identity, limits._process_state])
def test_a_process_reaped_mid_read_counts_as_gone(monkeypatch, reader) -> None:
"""Reading /proc/PID/stat of a just-reaped process raises ESRCH, not ENOENT."""

def reaped(self, *args, **kwargs):
raise ProcessLookupError(3, "No such process")

monkeypatch.setattr(limits.Path, "read_text", reaped)
assert reader(os.getpid()) is None
Loading