Resource Leaks: Files not closed properly in multiple modules
Open
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 1.2k
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 16
Description
Summary
Some Nettacker modules use open().read() without context managers, which can leave file handles open and cause resource leaks. This can lead to exhaustion of file descriptors in long‑running processes.
Problem
The following module contain unsafe file reads:
| File | Fix Applied |
|---|---|
nettacker/lib/html_log/log_data.py |
HTML template reads |
nettacker/lib/graph/d3_tree_v1/engine.py |
D3 tree template read |
nettacker/lib/compare_report/engine.py |
Compare report template read |
Resolution
Replace all bare open() calls with context managers:
# Before (unsafe)
content = open(filename).read()
# After (safe)
with open(filename) as f:
content = f.read()
Testing
-
Add new pytest tests under tests/lib/ to confirm:
-
Files are read correctly.
-
File handles are closed after reading.
-
Edge cases (empty file, missing file) are handled properly.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.