mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #4654] [Engine] the sampler and the HIP properties probe never call close() - ResourceWarning lines on every Minimal serving runtime run #2112
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#2112
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
Originally created by @TheHubUser4860938 on GitHub (Oct 30, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/4654
Problem and result. The
Minimal serving runtimejob prints the sameResourceWarninglines onevery run. Six
open()calls sit inside an expression, so nothing ever callsclose()on them:The patch closes all six and changes no answer.
Where they are (line numbers at
v0.2.8):serve/telemetry.py:458_cpu_topology()- one leaked handle percpu*/topology/physical_package_idglob hit. A 4-CPU runner prints four lines; this 16-CPU box leaks sixteen per call. Read from the
code, not measured as a cost:
_cpu_topology()is called twice in the samestaticdict(
socketsandnuma_nodes), so every CPU directory is read twice at each sampler start.serve/telemetry.py:476_cpu_name()- the/proc/cpuinfoscan. It reports at 478, thereturninside the loop, not at the
open(): the loop's iterator still holds the file when the frame isreleased. Worth knowing, because the line number in a report points away from the line to fix.
serve/telemetry.py:495_CpuRamFallback._times()-/proc/stat.sample()reaches the fallbackonce a second when psutil is absent (
serve/telemetry.py:633), and_CpuRamFallback.cpu()calls_times()again, so a second of sampling is two/proc/statreads plus one/proc/meminfo.serve/telemetry.py:522_CpuRamFallback.ram()-/proc/meminfo. Same defect, and it neverprinted in the log above: the log understates the set by one reader.
serve/server.py:3364hip_speed_scores()andserve/server.py:3401hip_gpu_archs()- thepropertiesprobe, both copies. In the test job these read a faked sysfs root(
/tmp/tmpXXXX/0/propertiesin the log), which is why they print on a machine with no AMD card.Measured on this box (Arch Linux, CPython 3.14.8, AMD Ryzen 7 9800X3D, 16 logical CPUs; both
versions loaded into one process so the reads are back to back against the same live
/proc, andthe same probe re-run against the pure
v0.2.8tag in a throwaway worktree):warningscaptured: 800 before, 0 after. The 800is arithmetic rather than a guess: 40 rounds x 20 files, where 20 = 16 per-CPU topology files +
cpuinfo + stat + stat again through
cpu()+ meminfo. On the pure tag: 800 as released, 0 with thepatch applied, and
git apply --checklands clean on upstream's bytes._cpu_name()returnsAMD Ryzen 7 9800X3D 8-Core Processor,_cpu_topology()returns(1, 1),cpu()returns0.0,ram()returns(119748005888, 134679015424)._times()+ram()with no collection at all hold +0 descriptors on/proc/self/fd, beforeand after: CPython decrefs the temporary at the end of the statement and the descriptor goes with
it. The warnings do not need the collector either - 40 rounds with
gc.collect()and 40 roundswithout it both give 800. So
ResourceWarninghere is the interpreter's "nobody calledclose()"complaint, i.e. hygiene and log noise, not fd pressure. On an interpreter without prompt
deallocation the same six would be a real leak; this box runs CPython only, so that is not tested.
serve.test_parallel,test_replicas,test_responses,test_security,test_server,test_session_save_retry,test_gpu_roles_server,test_vram:Ran 504 tests ... OK (skipped=1)in 202.9 s.unittest discover -s serve -p 'test_*.py'):Ran 1589 tests ... OK (skipped=17)in 464.2 s, and its log carries 5unclosed filelines where the same command on the unpatched tree carried 121 - 108 of them on a/procor/syspath. A 4-CPU runner prints 4 of those, which is what the quoted log shows; a 16-CPU box prints 108. The 5 that remain are 4serve/lifeline.py:59pipe descriptors and one stdlib frame, none of them a site this patch touches.The patch. Six
with-statements, nothing else. Sites that had noencodingargument were leftwithout one on purpose, so this is a lifetime change only and not a locale change; both
try/except (OSError, ValueError)shapes still catch what they caught, and a missingpropertiesfile behaves as before.
Limits, and what this does not claim.
/procand/sysbranches; the registry andctypesarms above them and the macOSsysctlarm are untouched.serve/lifeline.py:59warning that prints in the same job names an unnamed descriptor(fd 8, 9, 10 - pipes) and points at whatever frame released it. Different shape, not claimed here.
start_of()handle in this same family. This is the sampler andthe HIP probe, which that thread did not cover - its own body says "the sampler half has no
existing thread", and
ResourceWarningappears in no issue title (search: repo:Niko1221/Strata ResourceWarning in:titlereturns 0).How to see it.
python -X dev -m unittest discover -s serve -p 'test_*.py'prints them; or40 rounds of the five readers with
warnings.simplefilter("always")and countResourceWarning.— posted from the Strata-Mnemosyne fork (
memory-core, merged to v0.2.8 today). Numbers are ours,produced on the hardware named above.
@XiaoBinGan commented on GitHub (Nov 2, 2026):
This is fixed on main by
5c0259e2("Server: the sampler's and the HIP probe's files are closed after reading… (#4654)"): the sampler's four reads and the HIP probe's two properties reads all close their handle now, and serve/test_resource_warnings.py was added for it.My pull request that carried the same fix (#4791) is closed as superseded — nothing left to merge for this one.