LocalDNS.wtf
Advanced

Registry Limitations

Understanding the registry state management architecture, limitations, and implemented safety fixes.

Registry State Management

The Registry class uses a single JSON file (~/.localdns/registry.json) for all state storage. Multiple processes (daemon, CLI commands) create separate Registry instances that all read/write to this shared file.

Implemented Safety Fixes

File Locking

Uses proper-lockfile with retry logic (10 retries, 50ms-500ms exponential backoff). Prevents concurrent write conflicts.

Automatic Backups

A backup at ~/.localdns/registry.json.backup is created before every write operation. Automatic restoration on corruption detection.

Optimistic Locking

Re-reads file before write and merges changes at domain level. Last write wins per domain, but no data loss.

File Validation & Recovery

JSON parsing with error handling, automatic fallback to backup on corruption, and empty file detection.

Current Safety Assessment

AspectStatusNotes
Concurrent WritesSafeFile locking prevents conflicts
Atomic OperationsSafeLock ensures atomicity
Data IntegritySafeValidation + backup recovery
RecoverySafeAutomatic backup restoration
Conflict ResolutionModerateDomain-level merging (last write wins)

Remaining Limitations

  1. Domain-level conflicts: If two processes update the same domain simultaneously, last write wins (but no data loss)
  2. Settings conflicts: Settings updates may overwrite concurrent changes
  3. Performance: File locking adds ~50-500ms overhead per write
  4. Lock cleanup: Stale locks handled with stale detection

Migration Path

The current implementation is production-ready for single-user scenarios. For multi-user or high-concurrency:

  1. Short-term: Current implementation is sufficient
  2. Medium-term: Add version numbers for better conflict detection
  3. Long-term: Migrate to SQLite for ACID guarantees