Close profiler thread handles when report writing fails #242

Open
github-bot wants to merge 1 commit from github-bot/gh-242 into main AGit
Owner

@⁠feanorsun on GitHub · 2026-11-26 12:27 UTC · original
feanorsun:fix/profile-thread-handle-lifetime → main · +67 −4 · 1 files · 1 commits · open

Refs #227

This addresses the Profile thread handles item reported by kekonn. Thanks to kekonn for tracing the leak to the report writer.

choose keeps each opened thread handle in a profile record. Previously, write closed the handle only after writing that record's line. If File::create failed, every open handle leaked. An early write error could also leave the remaining handles open.

Each Thread now closes its non-null handle on drop. The writer only borrows the records, so returning an I/O error follows the same cleanup path as writing the full report. A failed OpenThread leaves a null handle that the destructor skips.

Windows verification

cargo test --offline --locked -j 1 -p victory-loader --features diagnostics --lib profile::tests -- --list
cargo test --offline --locked -j 1 -p victory-loader --features diagnostics --lib profile::tests -- --test-threads=1 --nocapture

The filter listed and ran three tests. Before the fix, the existing parser test passed and both new regressions failed. A missing parent directory left the handle open after the profile was dropped. A successful write closed the handle while the profile still owned it.

After the fix, all three passed. The tests compare the recorded handle against a separate handle to the same finished thread in the test process, both after write returns and after the records are dropped. They also check the report text and the NotFound error. The scheduled sampler was never started.

**@⁠feanorsun** on GitHub · 2026-11-26 12:27 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/242) `feanorsun:fix/profile-thread-handle-lifetime` → `main` · +67 −4 · 1 files · 1 commits · open Refs #227 This addresses the **Profile thread handles** item reported by kekonn. Thanks to kekonn for tracing the leak to the report writer. `choose` keeps each opened thread handle in a profile record. Previously, `write` closed the handle only after writing that record's line. If `File::create` failed, every open handle leaked. An early write error could also leave the remaining handles open. Each `Thread` now closes its non-null handle on drop. The writer only borrows the records, so returning an I/O error follows the same cleanup path as writing the full report. A failed `OpenThread` leaves a null handle that the destructor skips. ## Windows verification ```powershell cargo test --offline --locked -j 1 -p victory-loader --features diagnostics --lib profile::tests -- --list cargo test --offline --locked -j 1 -p victory-loader --features diagnostics --lib profile::tests -- --test-threads=1 --nocapture ``` The filter listed and ran three tests. Before the fix, the existing parser test passed and both new regressions failed. A missing parent directory left the handle open after the profile was dropped. A successful write closed the handle while the profile still owned it. After the fix, all three passed. The tests compare the recorded handle against a separate handle to the same finished thread in the test process, both after `write` returns and after the records are dropped. They also check the report text and the `NotFound` error. The scheduled sampler was never started.
Keep each handle open until its profile record is dropped. Cover successful output and a missing parent directory with real handles to a thread in the test process.

Thanks to kekonn for reporting the leak in #227.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 12:30:58 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/242/head:github-bot/gh-242'
git switch 'github-bot/gh-242'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-242'
git switch 'github-bot/gh-242'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-242'
git switch 'github-bot/gh-242'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-242'
git switch 'main'
git merge --squash 'github-bot/gh-242'
git switch 'main'
git merge --ff-only 'github-bot/gh-242'
git switch 'main'
git merge 'github-bot/gh-242'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.