fix: close SQLite connections on exception in calculate_table_hash and _get_count#770
Conversation
…d _get_count Fixes Scottcjn#767 Both calculate_table_hash() and _get_count() in RustChainSyncManager opened a SQLite connection with _get_connection() but relied on reaching conn.close() at the bottom of the function. Any exception raised by cursor.execute() or fetchall() / fetchone() would bypass conn.close(), silently leaking the connection. SQLite limits the number of open connections per process. Under sustained error conditions (e.g. disk I/O errors, locked DB) repeated calls would exhaust that limit and make the node unable to open any new database connections. Wrap all cursor operations in try/finally blocks to guarantee conn.close() is always called, mirroring the pattern already used in apply_sync_payload and _load_table_schema.
Scottcjn
left a comment
There was a problem hiding this comment.
Clean, correct fix. try/finally pattern matches existing apply_sync_payload and _load_table_schema. Prevents connection leaks under sustained error conditions.
Verdict: MERGE — 10 RTC bounty (micro fix, real bug).
🤖 Reviewed with GPT-5.4 + Claude Opus dual-brain analysis
|
Merged! 🎉 10 RTC bounty approved for this fix. Please share your RustChain wallet address (or miner ID) so we can send the payment. You can create one with the wallet CLI or just pick a wallet name and we'll set it up. Your other PRs (#769: 50 RTC, #768: 15 RTC) are also merged — total: 75 RTC. We'll batch it all in one transfer once we have your wallet. |
|
Thanks for merging! Here is the wallet for the 75 RTC payout (batch all 3 PRs): RustChain Wallet: If a full RTC wallet address is needed, please let me know and I can generate one via the wallet CLI. Ready whenever you are! |
|
75 RTC sent to Breakdown:
Thanks for the solid contributions! |
|
Your 75 RTC payment is already in the pending queue (pending #778). Transfers auto-confirm after 24 hours via cron. You should see it in your Thanks for the solid PRs — all 3 merged. |
…d _get_count (Scottcjn#770) Fixes Scottcjn#767 Both calculate_table_hash() and _get_count() in RustChainSyncManager opened a SQLite connection with _get_connection() but relied on reaching conn.close() at the bottom of the function. Any exception raised by cursor.execute() or fetchall() / fetchone() would bypass conn.close(), silently leaking the connection. SQLite limits the number of open connections per process. Under sustained error conditions (e.g. disk I/O errors, locked DB) repeated calls would exhaust that limit and make the node unable to open any new database connections. Wrap all cursor operations in try/finally blocks to guarantee conn.close() is always called, mirroring the pattern already used in apply_sync_payload and _load_table_schema. Co-authored-by: wsimon1982 <wsimon1982@googlemail.com>
Fixes #767
Problem
calculate_table_hash()and_get_count()innode/rustchain_sync.pyopened a SQLite connection but relied on reachingconn.close()at the end of the function. Any exception (disk I/O error, locked DB, etc.) would bypass the close call, leaking the connection. Under sustained error conditions this exhausts the SQLite connection limit and the node can no longer open new DB connections.Fix
Wrap all cursor operations in
try/finallyblocks soconn.close()is guaranteed, matching the pattern already used inapply_sync_payloadand_load_table_schema.