Skip to content

Finalize SQLite statements at query scope exit - #86

Merged
Araq merged 4 commits into
Araq:masterfrom
elcritch:fix/sqlite-statement-lifetime
Oct 19, 2026
Merged

Araq merged 4 commits into
Araq:masterfrom
elcritch:fix/sqlite-statement-lifetime

Conversation

@elcritch

@elcritch elcritch commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Generated SQLite queries prepare a new statement for each execution, but only reset it afterward. The statements and their bound values remain allocated, causing native memory to grow on long-running connections and preventing those connections from closing cleanly.

Finalize each statement with nonraising deferred cleanup immediately after preparation. Cleanup runs on normal completion, binding and result-conversion failures, exceptions, and iterator break or early return. Scope query expressions locally and remove the unused statement preparation outside generated routines, while preserving execution-error reporting.

Server profiling showed live native heap growing to 2.64 GiB after 7,019 ingested records. A focused statement-cleanup experiment stayed around 26 MiB through 10,000 records. A full 10,000-record server run with the final fix peaked at 25.22 MiB and ended at 24.17 MiB, including slow or unavailable downstream services, recovery, and two idle minutes.

Add regression tests for repeated queries followed by connection closure, typed queries, generated procedures and iterators, unused routine declarations, constraint errors, and exceptional exits. SQLite and PostgreSQL suites pass in CI.

CI installs Atlas through its official install.sh script and runs the test suites through Atlas. Example builds also pass with Jester >=0.6.0, which avoids the removed stdlib scgi dependency in older releases.

@Araq
Araq merged commit 50626ac into Araq:master Oct 19, 2026
1 check 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