Skip to content

fix(#328): close file handle in readDataFile using context manager#377

Open
Anirudh77715 wants to merge 1 commit intoEAPD-DRB:mainfrom
Anirudh77715:feature/328-fix-file-handle-leak
Open

fix(#328): close file handle in readDataFile using context manager#377
Anirudh77715 wants to merge 1 commit intoEAPD-DRB:mainfrom
Anirudh77715:feature/328-fix-file-handle-leak

Conversation

@Anirudh77715
Copy link
Copy Markdown

@Anirudh77715 Anirudh77715 commented Mar 28, 2026

readDataFile used f.close without parentheses, meaning the file descriptor was never actually closed. Replaced with a with open() context manager that guarantees automatic closure.

Linked issue

Existing related work reviewed

  • Issues/PRs reviewed: None found after search

Overlap assessment

  • Classification: none
  • Overlapping items: none
  • Why this is not duplicate/superseded: no existing PR addresses the unclosed file handle in readDataFile

Why this PR should proceed

Issue #328 documents a confirmed bug where f.close (without parentheses) is a no-op, causing file descriptor leaks under repeated calls. This PR applies the standard Python fix using a with context manager.

Summary

  • What changed: Replaced bare f.close with with open() as f: context manager in readDataFile (API/Classes/Case/DataFileClass.py)
  • Why: f.close without () is a no-op — the file is never closed, leaking OS file handles under repeated calls

Validation

  • Tests added/updated (or not applicable)
  • Validation steps documented
  • Evidence attached (logs/screenshots/output as relevant)

Documentation

  • Docs updated in this PR (or not applicable)
  • Any setup/workflow changes reflected in repo docs

Scope check

  • No unrelated refactors
  • Implemented from a feature branch
  • Change is deliverable without upstream OSeMOSYS/MUIO dependency
  • Base repo/branch is EAPD-DRB/MUIOGO:main (not upstream)

Exception rationale

…nager

readDataFile used f.close without parentheses, meaning the file
descriptor was never actually closed. Replaced with a 'with open()'
context manager that guarantees automatic closure.
@github-actions github-actions bot added needs-intake-fix PR intake structure needs maintainer follow-up and removed needs-intake-fix PR intake structure needs maintainer follow-up labels Mar 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] File handle not closed in readDataFile causing potential file descriptor leak

1 participant