Skip to content

Prevent SQLite handle exhaustion from aborting processing runs - #2431

Merged
abrignoni merged 1 commit into
abrignoni:mainfrom
CyberMike81:codex/sqlite-record-cleanup
Oct 9, 2026
Merged

abrignoni merged 1 commit into
abrignoni:mainfrom
CyberMike81:codex/sqlite-record-cleanup

Conversation

@CyberMike81

Copy link
Copy Markdown
Contributor

Problem

During a Full File System extraction, iLEAPP stopped at powerlogGenerativeAssetLoad with OSError: [Errno 24] Too many open files. The entire processing run failed to complete, rather than only losing one PowerLog artifact. Opening a SQLite database failed first, then logging the error and the outer exception both failed because they needed another file descriptor.

One failed run is documented in the retained log. The examiner reports that an earlier attempt stopped at the same point; that earlier output was deleted before diagnosis.

get_sqlite_db_records returns a cursor without explicitly closing its connection. A synthetic reproduction using the installed helper increased open descriptors from 4 to 104 after 100 reads; explicit garbage collection released them. The SQLite connection context manager in open_sqlite_db_readonly does not close the returned connection.

Change

  • Stream query results through a generator with cursor and connection cleanup in finally, including query/attach errors and explicit early closure.
  • Close the PowerLog table-name iterator explicitly when returning a matching table early.
  • Remember failed PowerLog gzip decompressions for the session and remove their partial temporary files. The same truncated archive was previously attempted 17 times in the failed run.
  • Add synthetic regression tests for cleanup and damaged-archive handling.

Callers that retain the iterator and stop early must close it, or use contextlib.closing. Rows remain sqlite3.Row objects, and the reader does not materialize the full result set. The newer logging recovery already present on main (#2403) is retained, not introduced by this PR.

Validation

  • Focused suite on current upstream plus this patch: 78 passed, 3 Windows-specific skips; changed-files lint introduced no warnings.

  • Synthetic cleanup tests cover successful and empty reads, invalid queries, invalid ATTACH, explicit early close, a consumer exception with closing, a logging exception, and a missing database.

  • 1,000 repeated reads with garbage collection disabled verify that connections are explicitly closed.

  • The rebuilt app processed 30 synthetic PowerLog databases, including plain and gzip inputs, preserved all 30 expected rows, logged one truncated archive once, and completed report generation without a traceback.

  • The locally rebuilt macOS app passed startup, empty-extraction report generation, raw-image walking, and GUI self-checks.

  • The examiner reran the real Full File System extraction locally. The run reached 1120/1120 scheduled artifacts and completed report generation in 22 minutes 27 seconds, with no Too many open files errors. Thirteen PowerLog exports contained 390,531 rows. powerlogGenerativeAssetLoad completed normally and reported no data found; the truncated archive was logged once and skipped.

The real-data check confirms run completion and exported counts, not an independent validation of every source record. A separate webkit_cache_records failure (AttributeError: 'str' object has no attribute 'hex') and Biome Maps intent-decoding warnings remained; those are outside this fix. The real rerun used the downloaded 2026.4.5-dev source plus this patch, including its newer upstream logging safeguard, so it was not a controlled test of only this patch against the older installed binary.

No case files, raw case logs, client identifiers, or local case paths are included. All committed fixtures are generated synthetically.

@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown

Thanks for the contribution!

The changed artifact modules cite public research images in their sample_data, so a maintainer can generate the test fixtures from those images. Nothing is needed from you, though you are welcome to add the fixtures yourself with admin/test/scripts/make_test_data.py.

  • powerlog.py: cites abe_ios16, ctf2020_ios12, dexter_ios18, felix23_ios16, felix_ios17, hickman_ios13, hickman_ios14, hickman_ios15, iphone11_ios17, iphone12_ios18, iphone14plus_ios18, magnet_ios16, otto_ios17; a maintainer can generate the fixture.

@github-actions github-actions Bot added the fixture-needed Cites a public image; a maintainer can generate the fixture label Oct 9, 2026
@abrignoni

Copy link
Copy Markdown
Owner

Thanks for finding this and for the careful write-up. The handle leak was real and your fix for it is merged: your commit went in through #2432.

I had to adjust one thing on top. As a generator the helper no longer ran the query at the call or returned [] on failure, and a couple of artifacts depend on that (one reads description from the result, one only probes the database). #2432 keeps your cleanup and puts that behavior back. Closing this one since the work is in.

@abrignoni
abrignoni merged commit 54ca355 into abrignoni:main Oct 9, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fixture-needed Cites a public image; a maintainer can generate the fixture

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants