[PR #612] [MERGED] hw_oracle: remove the temp workdir when the constructor fails (HW-ORACLE-WORKDIR-LEAK) #654

Closed
opened 2026-11-26 20:18:36 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/612
Author: @TuroYT
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/24/2026
Merged by: @ubiquitarianism

Base: main ← Head: fix/hw-oracle-workdir-leak


📝 Commits (1)

  • b68ce6c hw_oracle: remove the temp workdir when the constructor fails (HW-ORACLE-WORKDIR-LEAK)

📊 Changes

3 files changed (+187 additions, -13 deletions)

View changed files

➕ tests/test_hw_oracle_workdir_leak.py (+162 -0)
📝 tools/hw_oracle/drm.py (+15 -9)
📝 tools/hw_oracle/runner.py (+10 -4)

📄 Description

Claimed in the coordination issue as: HW-ORACLE-WORKDIR-LEAK (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7128008469)

What was wrong. DrmOracle.__init__ (tools/hw_oracle/drm.py, line 158) and Oracle.__init__ (tools/hw_oracle/runner.py, line 212) call tempfile.mkdtemp(...) and then can raise Unavailable: the launcher build, the arch lookup, the probe. close() removes the workdir, but it is never reached for an object whose constructor raised. Every skipped run (exit 77) therefore left a leonida-hw-oracle-* directory in the temp dir.

Reproduced on main (21625bca8) with the build step stubbed to raise: 3 skipped DrmOracle constructions left 3 directories, and 3 skipped Oracle constructions left 3 more.

What changed. In both constructors, the steps after mkdtemp run inside a try. On any BaseException the workdir is removed, but only if the constructor created it (owned = not workdir, the same test as workdir or mkdtemp(...)), and the exception is re-raised. A caller-supplied workdir is never removed. The new test is in tests/test_hw_oracle_workdir_leak.py; no existing file is touched beyond the two constructors.

Overlap with #297. #297 changes only tests/test_hw_oracle_drm.py, so the two PRs share no file. Its tests pass a caller-supplied workdir=, which this change leaves alone. I did not run a merge of the two branches.

Tested:

  • python3 -I tests/test_hw_oracle_workdir_leak.py on the unfixed constructors: FAILED (failures=5) (the 3 DrmOracle and 2 Oracle leak cases); the caller-workdir and success cases pass.
  • The same test after the fix: Ran 9 tests ... OK.
  • Repro with the build step stubbed to raise, TMPDIR set to an empty directory: before the fix 3 leftover directories (DrmOracle) and 6 in total; after the fix 0.
  • Edge runs on the fixed code: workdir="" (treated as not given) leaves nothing; a KeyboardInterrupt raised in the probe is re-raised and leaves nothing; an arch lookup failure after the build leaves nothing; a successful construction keeps its directory until close().
  • python3 -I tests/test_hw_oracle.py: OK (skipped=3); python3 -I tests/test_hw_oracle_asm_strip.py: OK; python3 -m compileall -q tools tests: ok; python3 -I tests/test_text_write_line_endings.py: OK; python3 -I scripts/check_no_game_data.py on the three changed files: exit 0.

Not tested: a real GPU or DRM run (the probe was replaced by a stub in every case), and the Windows path, which uses hw_oracle.c and was not exercised.

AI-assisted (Claude Code).


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/612 **Author:** [@TuroYT](https://github.com/TuroYT) **Created:** 11/24/2026 **Status:** ✅ Merged **Merged:** 11/24/2026 **Merged by:** [@ubiquitarianism](https://github.com/ubiquitarianism) **Base:** `main` ← **Head:** `fix/hw-oracle-workdir-leak` --- ### 📝 Commits (1) - [`b68ce6c`](https://github.com/ubiquitarianism/leonida/commit/b68ce6cccd696bad8150e18c5a8a4a2e5ea6cd73) hw_oracle: remove the temp workdir when the constructor fails (HW-ORACLE-WORKDIR-LEAK) ### 📊 Changes **3 files changed** (+187 additions, -13 deletions) <details> <summary>View changed files</summary> ➕ `tests/test_hw_oracle_workdir_leak.py` (+162 -0) 📝 `tools/hw_oracle/drm.py` (+15 -9) 📝 `tools/hw_oracle/runner.py` (+10 -4) </details> ### 📄 Description Claimed in the coordination issue as: HW-ORACLE-WORKDIR-LEAK (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7128008469) **What was wrong.** `DrmOracle.__init__` (`tools/hw_oracle/drm.py`, line 158) and `Oracle.__init__` (`tools/hw_oracle/runner.py`, line 212) call `tempfile.mkdtemp(...)` and then can raise `Unavailable`: the launcher build, the arch lookup, the probe. `close()` removes the workdir, but it is never reached for an object whose constructor raised. Every skipped run (exit 77) therefore left a `leonida-hw-oracle-*` directory in the temp dir. Reproduced on `main` (21625bca8) with the build step stubbed to raise: 3 skipped `DrmOracle` constructions left 3 directories, and 3 skipped `Oracle` constructions left 3 more. **What changed.** In both constructors, the steps after `mkdtemp` run inside a `try`. On any `BaseException` the workdir is removed, but only if the constructor created it (`owned = not workdir`, the same test as `workdir or mkdtemp(...)`), and the exception is re-raised. A caller-supplied `workdir` is never removed. The new test is in `tests/test_hw_oracle_workdir_leak.py`; no existing file is touched beyond the two constructors. **Overlap with #297.** #297 changes only `tests/test_hw_oracle_drm.py`, so the two PRs share no file. Its tests pass a caller-supplied `workdir=`, which this change leaves alone. I did not run a merge of the two branches. Tested: - `python3 -I tests/test_hw_oracle_workdir_leak.py` on the unfixed constructors: `FAILED (failures=5)` (the 3 `DrmOracle` and 2 `Oracle` leak cases); the caller-workdir and success cases pass. - The same test after the fix: `Ran 9 tests ... OK`. - Repro with the build step stubbed to raise, `TMPDIR` set to an empty directory: before the fix 3 leftover directories (DrmOracle) and 6 in total; after the fix 0. - Edge runs on the fixed code: `workdir=""` (treated as not given) leaves nothing; a `KeyboardInterrupt` raised in the probe is re-raised and leaves nothing; an arch lookup failure after the build leaves nothing; a successful construction keeps its directory until `close()`. - `python3 -I tests/test_hw_oracle.py`: `OK (skipped=3)`; `python3 -I tests/test_hw_oracle_asm_strip.py`: `OK`; `python3 -m compileall -q tools tests`: ok; `python3 -I tests/test_text_write_line_endings.py`: `OK`; `python3 -I scripts/check_no_game_data.py` on the three changed files: exit 0. Not tested: a real GPU or DRM run (the probe was replaced by a stub in every case), and the Windows path, which uses `hw_oracle.c` and was not exercised. AI-assisted (Claude Code). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:18:36 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#654
No description provided.