fix(storage): detect and clear stale RocksDB LOCK files on Windows#810
Closed
sliverp wants to merge 1 commit intovolcengine:mainfrom
Closed
fix(storage): detect and clear stale RocksDB LOCK files on Windows#810sliverp wants to merge 1 commit intovolcengine:mainfrom
sliverp wants to merge 1 commit intovolcengine:mainfrom
Conversation
On Windows, crashed or exited processes leave behind stale RocksDB LOCK files that block all subsequent sessions from opening the local vector database. This is especially common with hook-based architectures (Claude Code hooks, MCP stdio servers) where many short-lived Python processes repeatedly open and close the same DB. Add _clear_stale_rocksdb_locks() to local_store.py, called before PersistStore creation. On Windows, os.remove() on a file held by a live process raises PermissionError, providing an atomic staleness check: - remove succeeds → stale lock, safe to clean up - PermissionError → live process, leave it alone On non-Windows platforms the function is a no-op (the issue doesn't manifest due to Unix inode semantics). Added 5 tests covering removal, platform skip, PermissionError handling, empty directory, and nonexistent path. Closes volcengine#650 Ref volcengine#473, volcengine#576
Collaborator
|
Failed to generate code suggestions for PR |
Collaborator
|
Thanks for contributing the code. This fix is similar to another previous code(https://github.com/volcengine/OpenViking/pull/798/changes ) fix, and I will have the person who wrote that code make the corresponding modifications based on this implementation. I'm closing this PR for now. |
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.
Problem
On Windows, when using OpenViking in local mode (
SyncOpenVikingwithPersistStore), crashed or exited processes leave behind stale RocksDB LOCK files. All subsequent sessions fail with:This is especially common with hook-based architectures (Claude Code hooks, MCP stdio servers) where many short-lived Python processes repeatedly open and close the same database. Even calling
client.close()may not release the OS file handle until the Python process fully exits.Root Cause
RocksDB creates a LOCK file when opening a database. On Windows:
client.close(), the OS file handle may persist until process exitPermissionErrorSolution
Add
_clear_stale_rocksdb_locks()inlocal_store.py, called before creatingPersistStore. The function leverages Windows file semantics for an atomic staleness check:os.remove()succeeds → no process holds the file → stale lock → safe to removeos.remove()raisesPermissionError→ live process holds the file → leave it aloneOn non-Windows platforms, the function is a no-op (Unix inode semantics mean the issue doesn't manifest).
Safety: RocksDB LOCK files are purely advisory (0-byte, contain no data). All actual data lives in SST files, WAL logs, and MANIFEST.
Tests
Added 5 tests in
tests/storage/test_stale_rocksdb_lock.py:test_removes_stale_locks_on_windows— verifies cleanup on Windowstest_skips_on_non_windows— verifies no-op on macOS/Linuxtest_handles_permission_error_gracefully— verifies live locks are kepttest_handles_empty_directory— edge casetest_handles_nonexistent_path— edge caseCloses #650
Ref #473, #576