fix(audio2x-common): close file handles and handle missing trtexec in… - #8
Open
andrewwhitecdw wants to merge 1 commit into
Open
fix(audio2x-common): close file handles and handle missing trtexec in…#8andrewwhitecdw wants to merge 1 commit into
andrewwhitecdw wants to merge 1 commit into
Conversation
Author
|
Closing this sweep-generated PR: PR has 2 commits; sweep requires exactly one commit per PR. It does not meet the sweep requirements (single signed-off commit). |
… get_trt_cache_path
## Summary
`get_trt_cache_path()` in `audio2x-common/scripts/audio2x/data_utils.py`
(used to hash the ONNX model + trtexec binary + args into a TRT engine
cache key) leaks two file handles, and crashes with a confusing
`TypeError: expected str, bytes or os.PathLike object, not NoneType` when
`trtexec` is not on `PATH` — a common situation since the TRT cache is an
opt-in development speedup (`A2X_SDK_USE_TRT_CACHE=true`).
## Root cause
```python
digest.update(open(onnx_model_fpath, "rb").read()) # handle never closed
digest.update(open(shutil.which("trtexec"), "rb").read()) # which() may return None -> TypeError
```
`shutil.which()` returns `None` when the executable is not found, and
`open(None, "rb")` raises `TypeError`, masking the actual problem (trtexec
missing).
## Fix
Read both files with `with open(...)` so handles are always closed, and
raise a descriptive `FileNotFoundError` when `shutil.which("trtexec")`
returns `None`.
## Testing
Exercised `get_trt_cache_path` directly with `uv run --with numpy`
(ephemeral env) against a fake `network.onnx` and a fake `trtexec` on
`PATH`:
- hash is deterministic for identical inputs: OK
- changing args after the first 3 (trtexec/onnx/output paths) changes the
hash: OK
- with `trtexec` removed from `PATH`:
- after fix: raises `FileNotFoundError("trtexec not found in PATH...")`
- before fix (verified with the change stashed): raises
`TypeError: expected str, bytes or os.PathLike object, not NoneType`,
confirming the bug is pre-existing
⚠️ The project's full C++/CUDA test suite cannot run locally (requires
CUDA + TensorRT + generated test data); this change is confined to a
pure-Python helper that was tested in isolation.
## Why existing tests missed it
The TRT cache path is only exercised when `A2X_SDK_USE_TRT_CACHE=true`,
which the header comment marks as an opt-in development speedup, and the
missing-`trtexec` case only occurs on machines without TensorRT installed.
Signed-off-by: Andrew White <andrewwhitecdw@users.noreply.github.com>
Signed-off-by: andrewwhitecdw <andrewwhitecdw@users.noreply.github.com>
andrewwhitecdw
force-pushed
the
sweep/bugfix-trt-cache-path
branch
from
August 18, 2026 00:21
b405fc4 to
61659e0
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.
… get_trt_cache_path
Summary
get_trt_cache_path()inaudio2x-common/scripts/audio2x/data_utils.py(used to hash the ONNX model + trtexec binary + args into a TRT engine cache key) leaks two file handles, and crashes with a confusingTypeError: expected str, bytes or os.PathLike object, not NoneTypewhentrtexecis not onPATH— a common situation since the TRT cache is an opt-in development speedup (A2X_SDK_USE_TRT_CACHE=true).Root cause
shutil.which()returnsNonewhen the executable is not found, andopen(None, "rb")raisesTypeError, masking the actual problem (trtexec missing).Fix
Read both files with
with open(...)so handles are always closed, and raise a descriptiveFileNotFoundErrorwhenshutil.which("trtexec")returnsNone.Testing
Exercised
get_trt_cache_pathdirectly withuv run --with numpy(ephemeral env) against a fakenetwork.onnxand a faketrtexeconPATH:trtexecremoved fromPATH:FileNotFoundError("trtexec not found in PATH...")TypeError: expected str, bytes or os.PathLike object, not NoneType, confirming the bug is pre-existingWhy existing tests missed it
The TRT cache path is only exercised when
A2X_SDK_USE_TRT_CACHE=true, which the header comment marks as an opt-in development speedup, and the missing-trtexeccase only occurs on machines without TensorRT installed.