-
Notifications
You must be signed in to change notification settings - Fork 9
Finalize prepared statements #1990
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This changes those to properly dispose of them. A future improvement is to only prepare the EXPORT statement once, and attach it to the Session or store.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 issue found across 1 file
Prompt for AI agents (all 1 issues)
Understand the root cause of the following 1 issues and fix them.
<file name="packages/memory/space.ts">
<violation number="1" location="packages/memory/space.ts:788">
Wrap this statement in a try/finally so stmt.finalize() always runs even if stmt.get throws; otherwise a failing query will leak the prepared statement.</violation>
</file>
React with 👍 or 👎 to teach cubic. Mention @cubic-dev-ai to give feedback, ask questions, or re-run the review.
packages/memory/space.ts
Outdated
| const of = transaction.sub; | ||
| const row = session.store.prepare(EXPORT).get({ the, of }) as | ||
| const stmt = session.store.prepare(EXPORT); | ||
| const row = stmt.get({ the, of }) as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrap this statement in a try/finally so stmt.finalize() always runs even if stmt.get throws; otherwise a failing query will leak the prepared statement.
Prompt for AI agents
Address the following comment on packages/memory/space.ts at line 788:
<comment>Wrap this statement in a try/finally so stmt.finalize() always runs even if stmt.get throws; otherwise a failing query will leak the prepared statement.</comment>
<file context>
@@ -763,9 +784,11 @@ const commit = <Space extends MemorySpace>(
const of = transaction.sub;
- const row = session.store.prepare(EXPORT).get({ the, of }) as
+ const stmt = session.store.prepare(EXPORT);
+ const row = stmt.get({ the, of }) as
| StateRow
| undefined;
</file context>
✅ Addressed in f3d9ad7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a PR: #1991 Always finalize prepared statements by adding try/finally (merges into #1990)
Review and merge it to apply the changes.
…hat I'm not using a generator function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No issues found across 1 file
ellyxir
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks so much better, thanks! and i like getting rid of the generator even though i like generators, good call
* Our existing code created prepared statements without finalizing them. This changes those to properly dispose of them. A future improvement is to only prepare the EXPORT statement once, and attach it to the Session or store. * Removed comment about finalize, since it's no longer applicable now that I'm not using a generator function. * better finally
This changes the places where we use prepared statements to properly dispose of them.
A future improvement is to only prepare the EXPORT statement once, and attach it to the Session or store.
I also converted the selectFacts to not use a generator, since it isn't needed there, and complicates the statement disposal.
Summary by cubic
Finalize all prepared statements to prevent resource leaks and improve stability in memory store operations. Also change selectFacts to return an array so statements can be properly finalized.
Bug Fixes
Refactors
Written for commit f3d9ad7. Summary will update automatically on new commits.