Skip to content

fix(dash-spv): degrade gracefully when advisory file locking is unsupported (Android)#841

Merged
xdustinface merged 1 commit into
devfrom
claude/compassionate-sutherland-6f951e
Jul 5, 2026
Merged

fix(dash-spv): degrade gracefully when advisory file locking is unsupported (Android)#841
xdustinface merged 1 commit into
devfrom
claude/compassionate-sutherland-6f951e

Conversation

@QuantumExplorer

Copy link
Copy Markdown
Member

Summary

Fixes #840.

On Android (target_os = "android") the Rust standard library does not implement flock-based advisory file locking — File::try_lock() is a compile-time stub that unconditionally returns ErrorKind::Unsupported. LockFile::new() treated any TryLockError::Error as fatal, so dash-spv storage init always failed with:

SPV error: Write failed: Failed to acquire lock: try_lock() not supported

This blocked the entire Core/SPV layer on Android — no header/filter sync, no balances, no L1 send. iOS, macOS, and Linux desktop were unaffected (their targets implement flock).

Fix

The lock file is only a best-effort guard against multiple processes sharing one data directory. On single-process platforms that lack advisory locking, proceeding without it is safe. This PR treats ErrorKind::Unsupported as non-fatal: skip the advisory lock with a tracing::warn! and continue.

  • WouldBlock (directory already in use) → still fatal (DirectoryLocked).
  • Genuine I/O errors → still fatal (WriteFailed).
  • Unsupported → warn and continue without the cross-process guard.
  • The fast path on desktop/iOS is unchanged.

Handling ErrorKind::Unsupported generically (rather than #[cfg(target_os = "android")]-gating) is more robust: it covers any non-flock target without special-casing.

Testing

The classification logic is extracted into a small classify_lock_result helper so the degradation path can be unit-tested with a synthesized Unsupported error — this never occurs naturally on Linux/macOS CI. Added tests cover all four outcomes:

  • lock acquired → Ok(true)
  • WouldBlockDirectoryLocked
  • UnsupportedOk(false) (non-fatal, skip)
  • genuine I/O error → WriteFailed

All existing lockfile tests continue to pass:

running 9 tests ... test result: ok. 9 passed; 0 failed

cargo fmt --check and cargo clippy -p dash-spv --all-targets --all-features are clean.

🤖 Generated with Claude Code

…ported

`LockFile::new()` treated any `TryLockError::Error` from `File::try_lock()`
as fatal. On Android (`target_os = "android"`) the Rust standard library
does not implement `flock`-based advisory locking and returns
`ErrorKind::Unsupported` at compile time, so SPV storage init always failed
with `Write failed: Failed to acquire lock: try_lock() not supported`,
blocking the entire Core/SPV layer on Android.

The lock file is only a best-effort guard against multiple processes sharing
one data directory. On single-process platforms that lack advisory locking,
proceeding without it is safe. Treat `ErrorKind::Unsupported` as non-fatal:
skip the lock with a warning and continue. Genuine I/O errors and the
already-locked (`WouldBlock`) case remain fatal, and the fast path on
desktop/iOS is unchanged.

Extract the classification into a `classify_lock_result` helper so the
degradation path can be unit-tested with a synthesized `Unsupported` error
(which never occurs naturally on Linux/macOS CI).

Fixes #840

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@QuantumExplorer, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 58 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8e39222c-e230-410b-96a9-0c0ecb74849c

📥 Commits

Reviewing files that changed from the base of the PR and between b0a909c and e0410be.

📒 Files selected for processing (1)
  • dash-spv/src/storage/lockfile.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/compassionate-sutherland-6f951e

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.

@codecov

codecov Bot commented Jul 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.47826% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.38%. Comparing base (b0a909c) to head (e0410be).

Files with missing lines Patch % Lines
dash-spv/src/storage/lockfile.rs 93.47% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #841      +/-   ##
==========================================
- Coverage   73.44%   73.38%   -0.07%     
==========================================
  Files         324      324              
  Lines       72577    72616      +39     
==========================================
- Hits        53306    53291      -15     
- Misses      19271    19325      +54     
Flag Coverage Δ
core 76.94% <ø> (ø)
ffi 46.84% <ø> (-1.14%) ⬇️
rpc 20.00% <ø> (ø)
spv 90.61% <93.47%> (+0.33%) ⬆️
wallet 72.61% <ø> (ø)
Files with missing lines Coverage Δ
dash-spv/src/storage/lockfile.rs 94.78% <93.47%> (+1.36%) ⬆️

... and 23 files with indirect coverage changes

@xdustinface
xdustinface merged commit 95d0813 into dev Jul 5, 2026
36 checks passed
@xdustinface
xdustinface deleted the claude/compassionate-sutherland-6f951e branch July 5, 2026 13:30
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.

dash-spv: SPV storage init fails on Android — File::try_lock() is unsupported on target_os="android"

2 participants