{"record":{"id":"44dd098d98dd82c4","repo":"benbjohnson/litestream","slug":"close-level-0-ltx-iterator-w","errorCode":null,"errorMessage":"close level 0 ltx iterator: %w","messagePattern":"close level 0 ltx iterator: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"replica.go","lineNumber":875,"sourceCode":"\t\t\t}\n\t\t}\n\t}\n}\n\n// applyNewLTXFiles polls for new LTX files and applies them to the database.\n// It starts from level 0 and falls back to higher levels if there are gaps\n// (e.g., level 0 files were compacted away).\nfunc (r *Replica) applyNewLTXFiles(ctx context.Context, f *os.File, afterTXID ltx.TXID, pageSize uint32) (ltx.TXID, error) {\n\tcurrentTXID := afterTXID\n\n\t// Poll level 0 for the most recent incremental files.\n\titr, err := r.Client.LTXFiles(ctx, 0, currentTXID+1, false)\n\tif err != nil {\n\t\treturn currentTXID, fmt.Errorf(\"list level 0 ltx files: %w\", err)\n\t}\n\tcloseLevel0 := func(retErr error) (ltx.TXID, error) {\n\t\tif closeErr := itr.Close(); closeErr != nil {\n\t\t\tcloseErr = fmt.Errorf(\"close level 0 ltx iterator: %w\", closeErr)\n\t\t\tif retErr != nil {\n\t\t\t\treturn currentTXID, errors.Join(retErr, closeErr)\n\t\t\t}\n\t\t\treturn currentTXID, closeErr\n\t\t}\n\t\treturn currentTXID, retErr\n\t}\n\n\tvar sawLevel0 bool\n\tfor itr.Next() {\n\t\tsawLevel0 = true\n\t\tinfo := itr.Item()\n\n\t\t// If there's a gap, try to fill it from higher compaction levels.\n\t\tif info.MinTXID > currentTXID+1 {\n\t\t\tbridgedTXID, err := r.fillFollowGap(ctx, f, currentTXID, info.MinTXID, pageSize)\n\t\t\tif err != nil {\n\t\t\t\treturn closeLevel0(err)","sourceCodeStart":857,"sourceCodeEnd":893,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/replica.go#L857-L893","documentation":"The deferred close of the level-0 LTX iterator in applyNewLTXFiles returned an error. The listing had already been consumed, so this indicates a resource teardown failure on the backend connection — usually a dropped connection during Close.","triggerScenarios":"Thrown at replica.go:875 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check backend connection stability","The follow loop retries on the next poll interval"],"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-14T00:17:10.932Z"}