fix: address security and correctness issues in file persistence (#300)#307
Closed
fuziontech wants to merge 2 commits intomainfrom
Closed
fix: address security and correctness issues in file persistence (#300)#307fuziontech wants to merge 2 commits intomainfrom
fuziontech wants to merge 2 commits intomainfrom
Conversation
Add a `file_persistence` config option (YAML, env var, CLI flag) that stores DuckDB data in `<data_dir>/<username>.duckdb` instead of using per-connection in-memory databases. When enabled, DuckDB memory-maps the file and serves from RAM — giving Redis-like performance with disk durability. Data persists across client disconnects and duckgres restarts. The default behavior is unchanged: `file_persistence` defaults to false, so every connection still gets an isolated ephemeral in-memory DuckDB. Config resolution follows the existing YAML → env → CLI precedence: - YAML: `file_persistence: true` - Env: `DUCKGRES_FILE_PERSISTENCE=true` - CLI: `--file-persistence`
- Reject usernames containing path separators or ".." to prevent path traversal when constructing file-backed DB paths - Add shared *sql.DB pool per user so concurrent connections reuse the same DuckDB file handle instead of fighting over the write lock - Validate that file_persistence requires a non-empty data_dir at config resolution time, with a warning if misconfigured - Create data directory with os.MkdirAll before opening file-backed DBs - Skip DuckLake detach on cleanup for shared DBs (stays attached for pool lifetime) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up fixes for #300 (file persistence feature). Addresses the issues identified in review:
/,\, or..to prevent file-backed DB paths from escapingDataDir*sql.DBpool per user so multiple client connections reuse the same DuckDB file handle instead of fighting over the write lockfile_persistencewhendata_diris empty, preventing silent fallback to in-memoryos.MkdirAllthe data directory before opening file-backed DBsTest plan
/,\,..are rejected with clear erroracquireFileDBcalls return the same*sql.DB; DB closes after lastreleaseFileDBfile_persistence: truewithoutdata_dirproduces warning and disables persistenceDataDiris created automaticallygo test ./...)🤖 Generated with Claude Code