A busy sqlite read crashes the QRY store #28

Closed
opened 2026-12-01 18:03:02 +00:00 by mercurius · 3 comments
Member

Purpose (fix): a query that meets a locked sqlite file waits or answers an error, and never crashes QueryBookclub.BookclubQueryStore.

Seen: main push run 6465 (ci.yml on 8c86a55), job 26605, 1 failure in 281 tests. The failing test was a rebound Host reads nothing (apps/mcl_bookclub_phoenix_web/test/admin_api_test.exs:213, the read at :215). The error was CaseClauseError: no case clause matching :"$busy" in esqlite3.erl:236 (fetchall1/2), called from apps/query_bookclub/lib/query_bookclub/bookclub_query_store.ex:28. That handle_call passes :esqlite3.q/3 straight through, and the connection opened at :20 has no busy timeout. When the projection is writing the same file, a read gets $busy and the store process dies, so callers get an exit and not a 200/404. The same commit passed as PR run 6461, so this is timing on a loaded runner, but the crash is real.

The Erlang twin has the same shape: macula-services/mcl-bookclub apps/query_bookclub/src/bookclub_query_store.erl:37 (open) and :44-45 (handle_call). The twin issue is filed beside this one.

Done when: the store's connection waits on a locked file (a busy timeout on open) or the store answers {:error, :busy} without dying, and a test holds the write lock from a second connection and shows the read still answers.

Refs macula-services/mcl-bookclub-phoenix#4

Purpose (fix): a query that meets a locked sqlite file waits or answers an error, and never crashes QueryBookclub.BookclubQueryStore. Seen: main push run 6465 (ci.yml on 8c86a55), job 26605, 1 failure in 281 tests. The failing test was `a rebound Host reads nothing` (apps/mcl_bookclub_phoenix_web/test/admin_api_test.exs:213, the read at :215). The error was `CaseClauseError: no case clause matching :"$busy"` in esqlite3.erl:236 (fetchall1/2), called from apps/query_bookclub/lib/query_bookclub/bookclub_query_store.ex:28. That handle_call passes `:esqlite3.q/3` straight through, and the connection opened at :20 has no busy timeout. When the projection is writing the same file, a read gets `$busy` and the store process dies, so callers get an exit and not a 200/404. The same commit passed as PR run 6461, so this is timing on a loaded runner, but the crash is real. The Erlang twin has the same shape: macula-services/mcl-bookclub apps/query_bookclub/src/bookclub_query_store.erl:37 (open) and :44-45 (handle_call). The twin issue is filed beside this one. Done when: the store's connection waits on a locked file (a busy timeout on open) or the store answers {:error, :busy} without dying, and a test holds the write lock from a second connection and shows the read still answers. Refs macula-services/mcl-bookclub-phoenix#4
Author
Member

Flake attempt 1 (ruled a flake by Mars): main push run 6465, ci.yml on 8c86a55, job 26605 (gates). It failed on this crash: a rebound Host reads nothing, CaseClauseError :"$busy" from bookclub_query_store.ex:28. Rerunning only job 26605, once.

Flake attempt 1 (ruled a flake by Mars): main push run 6465, ci.yml on 8c86a55, job 26605 (gates). It failed on this crash: `a rebound Host reads nothing`, CaseClauseError :"$busy" from bookclub_query_store.ex:28. Rerunning only job 26605, once.
Author
Member

Flake attempt 1 result: rerun of job 26605 (main run 6465, 8c86a55) succeeded; run 6465 is now success. The crash this issue names stays open.

Flake attempt 1 result: rerun of job 26605 (main run 6465, 8c86a55) succeeded; run 6465 is now success. The crash this issue names stays open.
Author
Member

Landed: PR 29, main 04efa992f8. Commits: red first dfc2af3, fix 00ec229, Jupiter's review fixes 02719e3 and 04efa99. Done-when met: a read that meets a held write lock answers {:error, :busy} without the store dying (esqlite3 waits 2 s on open). bookclub_query_store_test.exs holds the lock from a second connection, checks that the writer can lock again and that a short lock is waited out, and traces that every statement prepared for a busy read is finalized. That last check pins the cause of the scheduler freeze a hand-rolled read loop caused. Erlang twin: macula-services/mcl-bookclub#15 (2b353a70).

Landed: PR 29, main 04efa992f87210a3a92f52e93808b04dee4ca6f2. Commits: red first dfc2af3, fix 00ec229, Jupiter's review fixes 02719e3 and 04efa99. Done-when met: a read that meets a held write lock answers {:error, :busy} without the store dying (esqlite3 waits 2 s on open). bookclub_query_store_test.exs holds the lock from a second connection, checks that the writer can lock again and that a short lock is waited out, and traces that every statement prepared for a busy read is finalized. That last check pins the cause of the scheduler freeze a hand-rolled read loop caused. Erlang twin: macula-services/mcl-bookclub#15 (2b353a70).
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
macula-services/mcl-bookclub-phoenix#28
No description provided.