hw_oracle: remove the temp workdir when the constructor fails (HW-ORACLE-WORKDIR-LEAK) #612
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/612"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ubiquitarianism/leonida. Originally posted by TuroYT on 2026-11-24T09:54:21Z.
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) andOracle.__init__(tools/hw_oracle/runner.py, line 212) calltempfile.mkdtemp(...)and then can raiseUnavailable: 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 aleonida-hw-oracle-*directory in the temp dir.Reproduced on
main(21625bca8) with the build step stubbed to raise: 3 skippedDrmOracleconstructions left 3 directories, and 3 skippedOracleconstructions left 3 more.What changed. In both constructors, the steps after
mkdtemprun inside atry. On anyBaseExceptionthe workdir is removed, but only if the constructor created it (owned = not workdir, the same test asworkdir or mkdtemp(...)), and the exception is re-raised. A caller-suppliedworkdiris never removed. The new test is intests/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-suppliedworkdir=, which this change leaves alone. I did not run a merge of the two branches.Tested:
python3 -I tests/test_hw_oracle_workdir_leak.pyon the unfixed constructors:FAILED (failures=5)(the 3DrmOracleand 2Oracleleak cases); the caller-workdir and success cases pass.Ran 9 tests ... OK.TMPDIRset to an empty directory: before the fix 3 leftover directories (DrmOracle) and 6 in total; after the fix 0.workdir=""(treated as not given) leaves nothing; aKeyboardInterruptraised in the probe is re-raised and leaves nothing; an arch lookup failure after the build leaves nothing; a successful construction keeps its directory untilclose().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.pyon 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.cand was not exercised.AI-assisted (Claude Code).