Skip to content

fix(storage): detect and clear stale RocksDB LOCK files on Windows#810

Closed
sliverp wants to merge 1 commit intovolcengine:mainfrom
sliverp:fix/stale-rocksdb-lock-detection
Closed

fix(storage): detect and clear stale RocksDB LOCK files on Windows#810
sliverp wants to merge 1 commit intovolcengine:mainfrom
sliverp:fix/stale-rocksdb-lock-detection

Conversation

@sliverp
Copy link

@sliverp sliverp commented Mar 20, 2026

Problem

On Windows, when using OpenViking in local mode (SyncOpenViking with PersistStore), crashed or exited processes leave behind stale RocksDB LOCK files. All subsequent sessions fail with:

IO error: .../LOCK: The process cannot access the file because it is being used by another process

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:

  1. Even after client.close(), the OS file handle may persist until process exit
  2. If the process crashes/is killed/times out, LOCK is never released
  3. Next process trying to open the same DB gets a PermissionError

Solution

Add _clear_stale_rocksdb_locks() in local_store.py, called before creating PersistStore. The function leverages Windows file semantics for an atomic staleness check:

  • os.remove() succeeds → no process holds the file → stale lock → safe to remove
  • os.remove() raises PermissionError → live process holds the file → leave it alone

On 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 Windows
  • test_skips_on_non_windows — verifies no-op on macOS/Linux
  • test_handles_permission_error_gracefully — verifies live locks are kept
  • test_handles_empty_directory — edge case
  • test_handles_nonexistent_path — edge case

Closes #650
Ref #473, #576

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
@CLAassistant
Copy link

CLAassistant commented Mar 20, 2026

CLA assistant check
All committers have signed the CLA.

@zhoujh01
Copy link
Collaborator

#798

@zhoujh01 zhoujh01 closed this Mar 20, 2026
@github-project-automation github-project-automation bot moved this from Backlog to Done in OpenViking project Mar 20, 2026
@zhoujh01 zhoujh01 reopened this Mar 20, 2026
@github-actions
Copy link

Failed to generate code suggestions for PR

@zhoujh01
Copy link
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.

@zhoujh01 zhoujh01 closed this Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Feature]: Stale RocksDB LOCK detection for local-mode multi-session safety (Windows)

3 participants