Skip to content

Close the scan archive before releasing its buffer - #597

Merged
omer-roth merged 1 commit into
cycodehq:mainfrom
eyal-benatav:fix-zipfile-del-traceback-on-empty-commit-range
Nov 18, 2026
Merged

omer-roth merged 1 commit into
cycodehq:mainfrom
eyal-benatav:fix-zipfile-del-traceback-on-empty-commit-range

Conversation

@eyal-benatav

Copy link
Copy Markdown
Contributor

Commit-range scans print Exception ignored in: <function ZipFile.__del__> tracebacks when the range has no files for the scan type. For example, an SCA commit-history scan of a range that doesn't touch any manifest or lockfile prints:

Exception ignored in: <function ZipFile.__del__ at 0x70a8d3599c60>
Traceback (most recent call last):
  File "zipfile/__init__.py", line 2042, in __del__
  File "zipfile/__init__.py", line 2059, in close
  File "tempfile.py", line 829, in seek
ValueError: I/O operation on closed file.

The scan result and exit code are correct; only stderr is noisy. It appears twice per scan, once for each placeholder archive.

Cause

  • commit_range_scanner.py creates from_commit_zipped_documents and to_commit_zipped_documents as placeholder InMemoryZip() instances. They are replaced by closed archives from zip_documents() only when there is something to scan.
  • With nothing to scan, the placeholders are kept, and their ZipFile is never closed.
  • InMemoryZip.cleanup() closes the SpooledTemporaryFile buffer but not the ZipFile. When the placeholder is garbage collected, ZipFile.__del__ calls close(), which seeks on the already-closed buffer and raises.

Fix

  • InMemoryZip.cleanup() now closes the archive before releasing the buffer. ZipFile.close() returns early when the archive is already closed, so archives built by zip_documents() are unaffected.
  • Added a test that runs cleanup() on an archive that was never closed and asserts that garbage collection raises no unraisable exception. It fails without the fix.

Testing

  • pytest tests: 1564 passed, 1 skipped
  • ruff check and ruff format --check are clean
  • Reproduced with cycode 3.25.1; the same code is unchanged in 3.28.0

@omer-roth
omer-roth merged commit 9f84a3f into cycodehq:main Nov 18, 2026
23 checks passed
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.

2 participants