fix(state): preserve SQLite locks during macOS permission hardening - #109752
Closed
JiehoonKwak wants to merge 1 commit into
Closed
JiehoonKwak wants to merge 1 commit into
JiehoonKwak wants to merge 1 commit into
Conversation
This was referenced Sep 13, 2026
Collaborator
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.
What does this PR do?
Preserves SQLite locks when SessionDB hardens state.db and its sidecar permissions on macOS. After #109509, the open/fchmod/close sequence can release locks belonging to existing SQLite connections in the same process. A competing connection can then remove live WAL/SHM files, leaving running sessions with DeletedWalGenerationError.
The shared permission helper now uses macOS pathname chmod with follow_symlinks=False for existing regular files. Only a missing database is opened, with exclusive creation and mode 0600. Existing symlinks and other non-regular files remain rejected. This fixes all macOS SessionDB callers, including gateway and Dashboard clients, without a client-specific workaround or a new dependency. Linux and Windows behavior is unchanged.
Related Issue
Related to #109728 and the macOS symptoms in #109641. Complements the Linux-only O_PATH implementation in #109734; macOS has no O_PATH, and an O_EVTONLY descriptor also releases these locks when closed. This does not implement the separate macOS preconnect deleted-sidecar detector requested in #109641.
Type of Change
Changes Made
How to Test
On macOS 26.6, both lock tests fail on unmodified main at b6b53c6 and pass with this patch. The competing writer stays blocked after permission hardening in both journal modes. All three new cases pass.
Broader focused run:
Result: 318 passed, 14 skipped, 1 failed. The failure is TestPerformancePragmasEndToEnd::test_configured_pragmas_reach_all_connection_types (read pool is None). The same full-file failure reproduces in an isolated worktree at unmodified b6b53c6; that test passes alone on both revisions. It is an existing test-order problem, not resolved by this patch.
Also verified with the installed Python 3.11 / SQLite 3.53.1 runtime: two SessionDB handles, repeated external SQLite reads and closes, then a session write and cross-handle readback; WAL/SHM inodes stayed unchanged. Ruff and git diff --check pass.
Checklist
Code
Documentation & Housekeeping