Skip to content

Fix: SQLite lock contention causing db read timeout.#193

Open
abishekve wants to merge 6 commits into
masterfrom
fix-1
Open

Fix: SQLite lock contention causing db read timeout.#193
abishekve wants to merge 6 commits into
masterfrom
fix-1

Conversation

@abishekve
Copy link
Copy Markdown
Collaborator

@abishekve abishekve commented May 12, 2026

Summary

Fixes an issue where /api/status/live remained in a pending state due to SQLite database lock contention caused by concurrent monitoring result writes.

Root Cause

  • Multiple monitoring workers were writing to check_result_raw concurrently.
  • SQLite allows only a single writer at a time.
  • Large check_result_raw table size increased query latency.
  • Read queries such as fetching latest timestamps were blocked by active writes.
  • This caused frontend requests to timeout after 30 seconds.

Changes

  • Serialized monitoring result writes using a background write queue.

  • Reduced concurrent SaveChangesAsync() contention.

  • Enabled SQLite WAL mode for improved read/write concurrency.

  • Added SQLite busy timeout handling.

  • Added indexes for:

    • check_result_raw(Ts DESC)
    • check_result_raw(EndpointId, Ts DESC)
  • Ensured scoped DbContext usage per monitoring operation.

Result

  • Prevents frequent SQLite Error 5: database is locked
  • Improves /api/status/live responsiveness
  • Reduces API timeout occurrences
  • Improves monitoring write stability under load

@github-actions github-actions Bot added the fix label May 12, 2026
@abishekve abishekve changed the title [wip]: Fix 1 Fix: SQLite lock contention causing db read timeout. May 12, 2026
abishekve added 3 commits May 12, 2026 14:25
…points, computes flap status in memory, and returns a HashSet<Guid>. The loop uses that pre-computed set — zero async calls inside the loop.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant