{"record":{"id":"aef3ee0af3977c2d","repo":"benbjohnson/litestream","slug":"stat-wal-before-sync-w","errorCode":null,"errorMessage":"stat wal before sync: %w","messagePattern":"stat wal before sync: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"db.go","lineNumber":1368,"sourceCode":"\t}, 0)\n}\n\nfunc (db *DB) verifyAndSyncWithExecutor(ctx context.Context, checkpointing bool, exec *syncExecutor, maxSyncWALBytes int64) (syncResult, error) {\n\tdb.setSyncDiagPhase(diagPhaseStatWAL, func(s *diagState) {\n\t\ts.txID = exec.pos.TXID + 1\n\t\ts.lastSyncedWALOffset = exec.state.lastSyncedWALOffset\n\t})\n\n\t// Use the last synced WAL offset as the logical size for checkpoint decisions.\n\t// This avoids using file size which may include stale frames with old salt\n\t// values after a checkpoint. See issue #997.\n\torigWALSize := exec.state.lastSyncedWALOffset\n\tif origWALSize == 0 {\n\t\t// First sync - use file size as fallback\n\t\tvar err error\n\t\torigWALSize, err = db.walFileSize()\n\t\tif err != nil {\n\t\t\treturn syncResult{}, fmt.Errorf(\"stat wal before sync: %w\", err)\n\t\t}\n\t}\n\n\t// Verify our last sync matches the current state of the WAL.\n\t// This ensures that the last sync position of the real WAL hasn't\n\t// been overwritten by another process.\n\tdb.setSyncDiagPhase(diagPhaseVerify)\n\tinfo, err := db.verifyWithExecutor(ctx, exec)\n\tif err != nil {\n\t\treturn syncResult{}, fmt.Errorf(\"cannot verify wal state: %w\", err)\n\t}\n\n\tdb.setSyncDiagPhase(diagPhaseSyncLTX, func(s *diagState) {\n\t\ts.txID = exec.pos.TXID + 1\n\t\ts.snapshotting = info.snapshotting\n\t\ts.reason = info.reason\n\t\ts.lastSyncedWALOffset = exec.state.lastSyncedWALOffset\n\t})","sourceCodeStart":1350,"sourceCodeEnd":1386,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/db.go#L1350-L1386","documentation":"On the first sync (last synced offset is 0), verifyAndSyncWithExecutor fell back to os.Stat on the WAL file and it failed. The WAL file is missing or unreadable at the moment sync begins — e.g. the database was deleted underneath Litestream.","triggerScenarios":"Thrown at db.go:1368 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the database and -wal files still exist and are readable","Restart litestream if the database was just recreated"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3","analyzedAt":"2026-09-06T18:29:25.564Z","contentChangedAt":"2026-09-06T18:29:25.564Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}