Skip to content

fix: resolve file descriptor leak in process_jar using context managers#121

Open
tirth707 wants to merge 1 commit intocytoscape:masterfrom
tirth707:fix/wsgi-file-leak
Open

fix: resolve file descriptor leak in process_jar using context managers#121
tirth707 wants to merge 1 commit intocytoscape:masterfrom
tirth707:fix/wsgi-file-leak

Conversation

@tirth707
Copy link
Copy Markdown

@tirth707 tirth707 commented Mar 5, 2026

Description

This PR resolves the file descriptor leak in the manifest parsing logic that contributes to WSGI worker exhaustion and "too many open files" server outages.

The fix transitions the zip archive handling in submit_app/processjar.py to a Python context manager (with statement). This guarantees that the operating system immediately releases the file handler as soon as the manifest is read, even if a subsequent parsing error triggers an exception.

Related Issue

Fixes #120

Testing & Proof

I verified this fix locally on macOS by profiling the Python process with lsof while simulating a loop of 500 malformed app uploads.

  • Before Fix: The process leaked over 500 file descriptors, reaching a peak of 552.
  • After Fix: The file descriptor count remained completely stable at 52 throughout the entire 500-upload loop.

Before and After Profiling Comparison:
Screenshot 2026-03-05 at 11 19 56 AM

Implementing this strict context management prevents resource exhaustion and improves the resilience of the submission pipeline.

Copilot AI review requested due to automatic review settings March 5, 2026 06:25
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a resource leak in the app submission pipeline by ensuring the JAR ZipFile is always closed after reading/parsing META-INF/MANIFEST.MF, preventing WSGI worker exhaustion under repeated malformed uploads.

Changes:

  • Wrap manifest read/parse in a with archive: context manager so the zip file descriptor is reliably released on exceptions.
  • Remove the manual archive.close() call (now handled by the context manager).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

Resource Leak: Unclosed file descriptors in jar manifest parsing

2 participants