Skip to content

Conversation

@xdustinface
Copy link
Collaborator

@xdustinface xdustinface commented Dec 27, 2025

Open lock file with read+write access and add test-only read_pid function that reads from the same file handle:

Fixes an issue in Windows tests encountered in the CI overhaul PR #253 where Windows prevents reading from the lockfile via a second file handle due to exclusive file lock:

thread 'storage::lockfile::tests::test_lock_file_contains_pid' (8952) panicked at dash-spv\src\storage\lockfile.rs:72:59:
Should read lock file: Os { code: 33, kind: Uncategorized, message: "The process cannot access the file because another process has locked a portion of the file." }

Summary by CodeRabbit

  • Refactor

    • Refined internal lock file creation mechanism with improved file handling semantics.
  • Tests

    • Enhanced lock file testing utilities.

✏️ Tip: You can customize this high-level summary in your review settings.

Fixes an issue encountered in the CI overhaul PR #253. Open lock file
with read+write access and add test-only `read_pid` function that reads
from the same file handle. This works on Windows where exclusive locks
prevent reading through another file handle:

```
thread 'storage::lockfile::tests::test_lock_file_contains_pid' (8952) panicked at dash-spv\src\storage\lockfile.rs:72:59:
Should read lock file: Os { code: 33, kind: Uncategorized, message: "The process cannot access the file because another process has locked a portion of the file." }
```
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 27, 2025

📝 Walkthrough

Walkthrough

File handling in the lock file module was refactored to use OpenOptions instead of File::create, enabling explicit control over file opening semantics including read/write/create/truncate flags. A test-only read_pid helper method was added to enable tests to read the PID value from the lock file consistently.

Changes

Cohort / File(s) Summary
Lock file I/O refactoring
dash-spv/src/storage/lockfile.rs
Replaced File::create with OpenOptions to enable explicit read/write/create/truncate semantics. Added read_pid test-only helper method to provide consistent PID reading for tests. Updated test utilities to use the new helper instead of direct file reads. Public signatures unchanged.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 The lock file now opens with OpenOptions' flair,
Read and write together, a perfect pair!
Tests use read_pid to peek inside,
No file gymnastics, just PID with pride.
Much elegant! Very safe! Such hop! 🎉

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding a test-only read_pid method to LockFile for cross-platform testing compatibility, which directly addresses the Windows file-locking issue outlined in the PR objectives.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/lockfile-read-pid

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
dash-spv/src/storage/lockfile.rs (1)

60-71: Consider adding documentation about the Windows-specific testing rationale.

The implementation is correct and properly scoped within the test module. However, adding a doc comment explaining that this method exists to avoid Windows exclusive-lock conflicts would improve maintainability.

📝 Suggested documentation improvement
     impl LockFile {
-        /// Reads the PID from the lock file.
+        /// Reads the PID from the lock file using the same file handle.
+        ///
+        /// This method is test-only and reads from the same file handle to avoid
+        /// Windows-specific issues where opening a second file handle fails due to
+        /// the exclusive file lock.
         fn read_pid(&mut self) -> std::io::Result<u32> {
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3884314 and e4f5d29.

📒 Files selected for processing (1)
  • dash-spv/src/storage/lockfile.rs
🧰 Additional context used
📓 Path-based instructions (5)
dash-spv/**/*.rs

📄 CodeRabbit inference engine (dash-spv/CLAUDE.md)

dash-spv/**/*.rs: Use async/await throughout the codebase, built on tokio runtime
Use Arc for trait objects to enable runtime polymorphism for NetworkManager and StorageManager
Use Tokio channels for inter-component message passing between async tasks
Maintain minimum Rust version (MSRV) of 1.89 and use only compatible syntax and features

Files:

  • dash-spv/src/storage/lockfile.rs
dash-spv/src/storage/**/*.rs

📄 CodeRabbit inference engine (dash-spv/CLAUDE.md)

Store headers in 10,000-header segments with index files in headers/ directory, filter headers and compact block filters in filters/ directory, and state in state/ directory

Files:

  • dash-spv/src/storage/lockfile.rs
**/*.{rs,toml}

📄 CodeRabbit inference engine (CLAUDE.md)

Never hardcode network parameters, addresses, or keys

Files:

  • dash-spv/src/storage/lockfile.rs
**/*.rs

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.rs: Use proper error types (thiserror) and propagate errors appropriately
Use tokio runtime for async operations
Use conditional compilation with feature flags for optional features
Write unit tests for new functionality
Use secure random number generation for keys
Never log or expose private keys
Code must target Rust 1.89 minimum supported version (MSRV)
Format code using cargo fmt
Pass clippy linting without warnings

**/*.rs: MSRV (Minimum Supported Rust Version) is 1.89; ensure compatibility with this version for all builds
Unit tests should live alongside code with #[cfg(test)] annotation; integration tests use the tests/ directory
Use snake_case for function and variable names
Use UpperCamelCase for types and traits
Use SCREAMING_SNAKE_CASE for constants
Format code with rustfmt before commits; ensure cargo fmt --all is run
Run cargo clippy --workspace --all-targets -- -D warnings for linting; avoid warnings in CI
Prefer async/await via tokio for asynchronous operations

Files:

  • dash-spv/src/storage/lockfile.rs
**/{dash-network,dash-spv,key-wallet}/**/*.rs

📄 CodeRabbit inference engine (CLAUDE.md)

Use async/await for async operations in network and wallet modules

Files:

  • dash-spv/src/storage/lockfile.rs
🧠 Learnings (2)
📚 Learning: 2025-06-26T15:54:02.509Z
Learnt from: DCG-Claude
Repo: dashpay/rust-dashcore PR: 0
File: :0-0
Timestamp: 2025-06-26T15:54:02.509Z
Learning: The `StorageManager` trait in `dash-spv/src/storage/mod.rs` uses `&mut self` methods but is also `Send + Sync`, and implementations often use interior mutability for concurrency. This can be confusing, so explicit documentation should clarify thread-safety expectations and the rationale for the API design.

Applied to files:

  • dash-spv/src/storage/lockfile.rs
📚 Learning: 2025-12-22T17:59:51.097Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-22T17:59:51.097Z
Learning: Applies to **/*.rs : Unit tests should live alongside code with `#[cfg(test)]` annotation; integration tests use the `tests/` directory

Applied to files:

  • dash-spv/src/storage/lockfile.rs
🧬 Code graph analysis (1)
dash-spv/src/storage/lockfile.rs (1)
dash-spv/src/storage/manager.rs (1)
  • new (63-127)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (18)
  • GitHub Check: fuzz (hashes_sha256)
  • GitHub Check: fuzz (hashes_sha512_256)
  • GitHub Check: fuzz (hashes_sha512)
  • GitHub Check: fuzz (hashes_json)
  • GitHub Check: fuzz (hashes_cbor)
  • GitHub Check: fuzz (hashes_ripemd160)
  • GitHub Check: fuzz (dash_outpoint_string)
  • GitHub Check: fuzz (dash_deserialize_address)
  • GitHub Check: fuzz (dash_deser_net_msg)
  • GitHub Check: fuzz (dash_deserialize_witness)
  • GitHub Check: fuzz (dash_script_bytes_to_asm_fmt)
  • GitHub Check: fuzz (dash_deserialize_block)
  • GitHub Check: fuzz (dash_deserialize_amount)
  • GitHub Check: Pre-commit (ubuntu-latest)
  • GitHub Check: SPV Components Tests
  • GitHub Check: Core Components Tests
  • GitHub Check: RPC Tests (stable, true)
  • GitHub Check: Pre-commit (macos-latest)
🔇 Additional comments (3)
dash-spv/src/storage/lockfile.rs (3)

3-3: LGTM: Import addition is appropriate.

The OpenOptions import is necessary for the new file opening approach and is correctly imported from std::fs.


17-22: LGTM: File opening logic correctly adds read capability.

The change from File::create to OpenOptions with explicit flags is correct. The flags read(true).write(true).create(true).truncate(true) maintain the original behavior while adding read capability, which enables reading the PID from the same file handle and resolves the Windows exclusive-lock conflict mentioned in the PR objectives.


89-90: LGTM: Test correctly uses the new read_pid method.

The test now reads the PID from the same file handle using read_pid(), which resolves the Windows-specific test failure. The addition of mut to the binding is necessary since read_pid() takes &mut self.

@xdustinface xdustinface changed the base branch from v0.41-dev to v0.42-dev December 30, 2025 22:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants