{"record":{"id":"57fdb85851bf1828","repo":"diegosouzapw/OmniRoute","slug":"db-wal-checkpoint-failed-during-close-checkpo","errorCode":null,"errorMessage":"[DB] WAL checkpoint failed during close (${checkpointMode}):","messagePattern":"\\[DB\\] WAL checkpoint failed during close \\((.+?)\\):","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/lib/db/core.ts","lineNumber":1437,"sourceCode":"}\n\nexport function closeDbInstance(options?: { checkpointMode?: CheckpointMode | null }): boolean {\n  clearDbHealthCheckScheduler();\n  clearWalTruncateScheduler();\n  const db = getDb();\n  if (!db) return false;\n\n  const checkpointMode = options?.checkpointMode ?? \"TRUNCATE\";\n\n  try {\n    if (checkpointMode) {\n      try {\n        if (checkpointDb(db, checkpointMode)) {\n          console.log(`[DB] SQLite WAL checkpoint completed (${checkpointMode}).`);\n        }\n      } catch (error: unknown) {\n        const message = error instanceof Error ? error.message : String(error);\n        console.warn(`[DB] WAL checkpoint failed during close (${checkpointMode}):`, message);\n      }\n    }\n  } finally {\n    try {\n      if (db.open) db.close();\n    } finally {\n      setDb(null);\n      // Module-level caches (prepared statements, schema-check memos — e.g.\n      // apiKeys.ts) are bound to the closed connection. Without this, a recreated\n      // DB (tests, backup restore of an older snapshot) hits \"no such column\"\n      // on the stale re-prepare path. backup.ts already does this on restore;\n      // close/reset must too (found by the 6A.1 orphan-test re-wire, 2026-06-09).\n      resetAllDbModuleState();\n    }\n  }\n\n  return true;\n}","sourceCodeStart":1419,"sourceCodeEnd":1455,"githubUrl":"https://github.com/diegosouzapw/OmniRoute/blob/a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d/src/lib/db/core.ts#L1419-L1455","documentation":"During graceful database shutdown (closeDbInstance), the final WAL checkpoint in the configured mode (default TRUNCATE) threw. The close path continues and closes the database anyway, so the WAL file may not have been fully checkpointed/truncated — potentially leaving a larger -wal file and a recovery pass on next open.","triggerScenarios":"Thrown at src/lib/db/core.ts:1437 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure no concurrent connections hold the database during shutdown","Run a manual checkpoint (PRAGMA wal_checkpoint(TRUNCATE)) before shutdown if it recurs","Check disk space and file permissions on the database directory"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d","analyzedAt":"2026-08-25T18:35:09.898Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}