Repository navigation
[Engine] close the six handles the sampler and the HIP probe leak (Fix #4654) - #4791
Open
XiaoBinGan wants to merge 1 commit into
Open
XiaoBinGan wants to merge 1 commit into
XiaoBinGan wants to merge 1 commit into
Conversation
…e open inside an expression Six open() calls sat inside an expression, so nothing ever called close() on them and the Minimal serving runtime job printed the same ResourceWarning lines on every run: the physical_package_id glob, /proc/cpuinfo, /proc/stat and /proc/meminfo in serve/telemetry.py, and the two properties files the HIP probe reads in serve/server.py. Each now runs under a with statement: telemetry.py reads the cpuinfo, stat and meminfo files through one, and server.py reads the two properties files through a small _read_lines() helper. No value, threshold or return path changes; the figures are the same ones in the same order.
XiaoBinGan
force-pushed
the
fix/close-leaked-handles
branch
from
October 31, 2026 10:14
36b5768 to
74c0f11
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem and result
The
Minimal serving runtimejob prints the sameResourceWarninglines on every run (#4654). Sixopen()calls satinside an expression, so no
close()ever ran:serve/telemetry.py— thephysical_package_idglob (one handle per CPU),/proc/cpuinfo,/proc/stat,/proc/meminfoserve/server.py— the twopropertiesfiles the HIP probe readsEach now runs under a
withstatement (or through a one-line_read_lines()helper for the twopropertiesreads).No value, threshold or return path changes: the same figures are parsed from the same lines in the same order.
Related discussion
#4654 — the report with the exact warning lines and the two sites in
server.py. A pytest run with-W error::ResourceWarningon the CI job is what the report suggests; this PR removes the leaks it names and does notchange the job.
Approach
Only the ownership of the handles changes:
and for the HIP probe:
The early
returninside the cpuinfo loop is kept; thewithcloses the file on the way out, which is the bug thereport describes (
_cpu_name()reports at thereturn, not at theopen()).Validation
Passed:
python -m pytest serve/test_monitor.py -qon this checkout (Python 3.11.16, Windows): 10 passed, 8subtests passed — the module these helpers live in imports and its monitor tests are unchanged.
Passed:
import serve.telemetryandimport serve.serverboth succeed after the change, and a grep for anopen(still inside an expression in
serve/telemetry.pynow finds none.Failed: none.
Not run: the
/procand/sysbranches themselves cannot be exercised on this Windows checkout (they are Linuxpaths), so the warnings the job reports are verified by reading the diff, not by reproducing them here. A Linux run with
-W error::ResourceWarningwould settle it, and the issue's own job is the natural place.Limits
propertiesreads are now one small helper rather than two identical comprehensions; if the reviewer preferspathlib.Path(...).read_text(...)inline, that is a one-line change each.