Skip to content

sqldb+docs: fix user pragma options for native SQL store, add mobile docs#10590

Closed
ziggie1984 wants to merge 2 commits intolightningnetwork:masterfrom
ziggie1984:fix-sqlite-temp-store
Closed

sqldb+docs: fix user pragma options for native SQL store, add mobile docs#10590
ziggie1984 wants to merge 2 commits intolightningnetwork:masterfrom
ziggie1984:fix-sqlite-temp-store

Conversation

@ziggie1984
Copy link
Collaborator

Summary

  • sqldb: pass user pragma options to native SQL store — The db.sqlite.pragmaoptions config flag was only being applied to the kvdb SQLite backend but not to the native SQL store (sqldb). This meant user-specified pragma options like temp_store=memory had no effect on the native SQL tables.

  • docs: add mobile SQLite considerations — Documents that temp_store=memory is required when running LND on Android/iOS via gomobile, explaining the root cause (SQLITE_IOERR_GETTEMPPATH, error code 6410).

Fixes #10558

Context

On Android (and iOS), the app sandbox prevents SQLite from accessing the system temporary directory. When neutrino's block header and compact filter header sync run concurrently and trigger more complex database transactions, SQLite attempts to write temp files and fails with SQLITE_IOERR_GETTEMPPATH (error 6410). This causes all retry attempts to exhaust, resulting in db tx retries exceeded and sync getting permanently stuck around block ~123,000.

The fix for the reporter's issue is to add the following to their LND config:

db.sqlite.pragmaoptions=temp_store=memory

Since neutrino only uses the kvdb backend (not native SQL), this config option already works today without this PR. However, this PR ensures the pragma options are also correctly passed through to the native SQL store for completeness, and adds documentation to help future mobile developers avoid this issue.

Test plan

  • Verified on Android emulator (arm64-v8a) that sync gets stuck at ~block 123,000 without temp_store=memory
  • Verified sync completes fully past block 937,000+ with temp_store=memory set via config
  • Verified go build ./... passes for the sqldb module

The SqliteConfig already supports user-configurable pragma options via
the `db.sqlite.pragmaoptions` config flag, and the kvdb sqlite backend
correctly applies them. However, the native SQL store (sqldb) was
ignoring cfg.PragmaOptions when constructing the DSN, meaning user
pragma settings only applied to the KV store but not to the native SQL
tables.

This is particularly important for mobile (Android/iOS) deployments
where `temp_store=memory` must be set to avoid SQLITE_IOERR_GETTEMPPATH
(error 6410) failures caused by the app sandbox preventing access to the
system temporary directory.
@gemini-code-assist
Copy link

Summary of Changes

Hello @ziggie1984, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances LND's database handling by ensuring user-defined SQLite pragma options are consistently applied across all database backends, including the native SQL store. Concurrently, it introduces crucial documentation for mobile developers, explaining how to configure SQLite to avoid common 'disk I/O error' issues on Android and iOS devices, thereby improving the reliability of LND on these platforms.

Highlights

  • Native SQL Store Pragma Options: Ensured that user-specified SQLite pragma options, such as 'temp_store=memory', are correctly applied to the native SQL database store, addressing a previous oversight where they were only applied to the kvdb backend.
  • Mobile SQLite Documentation: Added new documentation detailing critical SQLite considerations for mobile platforms (Android/iOS), specifically highlighting the requirement for 'temp_store=memory' to prevent 'SQLITE_IOERR_GETTEMPPATH' errors due to app sandbox restrictions.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • docs/sqlite.md
    • Added a new section "Mobile (Android/iOS) considerations" explaining the necessity of 'db.sqlite.pragmaoptions=temp_store=memory' for LND on mobile platforms.
    • Detailed the 'SQLITE_IOERR_GETTEMPPATH' error and how 'temp_store=memory' resolves sandbox restrictions.
  • sqldb/sqlite.go
    • Implemented a loop to iterate through 'cfg.PragmaOptions' and add each user-specified pragma option to the 'sqliteOptions' for the native SQL store.
Activity
  • Verified on an Android emulator that sync issues occur without 'temp_store=memory'.
  • Confirmed that sync completes successfully with 'temp_store=memory' enabled via config.
  • Ensured 'go build ./...' passes for the 'sqldb' module.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@ziggie1984 ziggie1984 self-assigned this Feb 18, 2026
@lightninglabs-deploy lightninglabs-deploy added the severity-high Requires knowledgeable engineer review label Feb 18, 2026
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly extends the user-configurable pragma options to the native SQL store, which was previously only available for the kvdb backend. The accompanying documentation for mobile-specific SQLite considerations is clear and will be very helpful for developers on those platforms. I have one minor suggestion to improve a comment to better align with the project's style guide.

Comment on lines +103 to +104
// Then we add any user specified pragma options. Note that these can
// be of the form: "key=value", "key(N)" or "key".

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This comment explains what the code does, but the LND style guide prefers comments that explain the intention or why. A more descriptive comment would be helpful here to explain why we are adding user-specified pragma options, providing more context to future developers.

Suggested change
// Then we add any user specified pragma options. Note that these can
// be of the form: "key=value", "key(N)" or "key".
// In addition to default pragmas, add any user-specified pragma options
// to allow for platform-specific customizations (e.g. for mobile).
References
  1. In-body comments should explain the intention of the code, not just what it does. The current comment explains what the code is doing, but not why it's important to add user-specified pragma options. (link)

Document that `temp_store=memory` is required when running LND on
Android/iOS via gomobile. Without it, SQLite fails with
SQLITE_IOERR_GETTEMPPATH (error 6410) because the app sandbox prevents
access to the system temporary directory.
@ziggie1984 ziggie1984 force-pushed the fix-sqlite-temp-store branch from 2cd855e to 1ad66ef Compare February 18, 2026 11:28
@lightninglabs-deploy
Copy link
Collaborator

🟠 PR Severity: HIGH

Auto-classified | 2 files | 27 lines changed

🟠 High (1 file)
  • sqldb/sqlite.go - SQL database operations (sqldb/* package)
🟢 Low (1 file)
  • docs/sqlite.md - Documentation

Analysis

This PR is classified as HIGH severity because it modifies sqldb/sqlite.go, which is part of the SQL database infrastructure (sqldb/* is categorized as HIGH). The changes involve fixing user pragma options for the native SQL store, which affects database configuration.

While the diff is small (6 lines in the sqldb package), any changes to database-related code require review by a knowledgeable engineer to ensure correctness and avoid potential data integrity issues.

The documentation changes in docs/sqlite.md add mobile-specific guidance but do not affect the overall severity classification.


To override, add a severity-override-{critical,high,medium,low} label.

@ziggie1984
Copy link
Collaborator Author

closing in favour of #10565

@ziggie1984 ziggie1984 closed this Feb 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-changelog no-itest severity-high Requires knowledgeable engineer review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug]: Android: SQLite: Neutrino some wallets having sync stuck at block 123000

2 participants