Close profiler thread handles when report writing fails #242

Open
feanorsun wants to merge 1 commit from upstream-pr/242 into main
feanorsun commented 2026-11-26 12:27:35 +00:00 (Migrated from github.com)

Imported from avatarmanz/VIctory-7900XTX. Originally posted by feanorsun on 2026-11-26T12:27:35Z.


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.

<!-- greyfinch-sync:avatarmanz/VIctory-7900XTX:issue:6626635500 --> Imported from [avatarmanz/VIctory-7900XTX](https://github.com/avatarmanz/VIctory-7900XTX/pull/242). Originally posted by [feanorsun](https://github.com/feanorsun) on 2026-11-26T12:27:35Z. --- 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.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/242:upstream-pr/242'
git switch 'upstream-pr/242'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/242'
git switch 'upstream-pr/242'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/242'
git switch 'upstream-pr/242'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/242'
git switch 'main'
git merge --squash 'upstream-pr/242'
git switch 'main'
git merge --ff-only 'upstream-pr/242'
git switch 'main'
git merge 'upstream-pr/242'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
avatarmanz/VIctory-7900XTX!242
No description provided.