Skip to content

Commit b089ada

Browse files
fix(shared): avoid waiting on busy WAL truncation
1 parent 71bdf16 commit b089ada

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

‎packages/shared/src/nodeSqliteClient.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,9 +541,16 @@ const finishTruncate = (truncateId) => {
541541
if (pendingTruncate === undefined || pendingTruncate.truncateId !== truncateId) return;
542542
const pending = pendingTruncate;
543543
parentPort.postMessage({ type: "truncate-start", truncateId });
544-
const busy = truncate.get().busy !== 0;
544+
let busy;
545+
// Admission is paused here; a pinned reader must not make truncation wait.
546+
db.exec("PRAGMA busy_timeout = 0;");
547+
try {
548+
busy = truncate.get().busy !== 0;
549+
} finally {
550+
db.exec("PRAGMA busy_timeout = 5000;");
551+
}
545552
const state = frames.get();
546-
const blocked = busy || (atCeiling(state) && state.checkpointed < state.log) || exceedsSizeLimit();
553+
const blocked = (atCeiling(state) && (busy || state.checkpointed < state.log)) || exceedsSizeLimit();
547554
pendingTruncate = undefined;
548555
parentPort.postMessage({
549556
type: "checkpoint",

0 commit comments

Comments
 (0)