{"record":{"id":"9bbd49c19ffc17a7","repo":"benbjohnson/litestream","slug":"new-ltx-encoder-w","errorCode":null,"errorMessage":"new ltx encoder: %w","messagePattern":"new ltx encoder: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"db.go","lineNumber":2144,"sourceCode":"\t}\n\tdefer func() { _ = os.Remove(tmpFilename) }()\n\tdefer func() { _ = ltxFile.Close() }()\n\n\tuid, gid := internal.Fileinfo(db.fileInfo)\n\t_ = os.Chown(tmpFilename, uid, gid)\n\n\tdb.Logger.Log(ctx, internal.LevelTrace, \"encode header\",\n\t\t\"txid\", txID.String(),\n\t\t\"commit\", commit,\n\t\t\"walOffset\", info.offset,\n\t\t\"walSize\", sz,\n\t\t\"salt1\", rd.salt1,\n\t\t\"salt2\", rd.salt2)\n\n\ttimestamp := time.Now()\n\tenc, err := ltx.NewEncoder(ltxFile)\n\tif err != nil {\n\t\treturn result, fmt.Errorf(\"new ltx encoder: %w\", err)\n\t}\n\tif err := enc.EncodeHeader(ltx.Header{\n\t\tVersion:   ltx.Version,\n\t\tFlags:     ltx.HeaderFlagNoChecksum,\n\t\tPageSize:  uint32(db.pageSize),\n\t\tCommit:    commit,\n\t\tMinTXID:   txID,\n\t\tMaxTXID:   txID,\n\t\tTimestamp: timestamp.UnixMilli(),\n\t\tWALOffset: info.offset,\n\t\tWALSize:   sz,\n\t\tWALSalt1:  rd.salt1,\n\t\tWALSalt2:  rd.salt2,\n\t}); err != nil {\n\t\tif isDiskFullError(err) {\n\t\t\treturn result, NewLTXError(\"stage-write\", tmpFilename, 0, uint64(txID), uint64(txID), fmt.Errorf(\"%w: %w\", ErrDiskFull, err))\n\t\t}\n\t\treturn result, fmt.Errorf(\"encode ltx header: %w\", err)","sourceCodeStart":2126,"sourceCodeEnd":2162,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/db.go#L2126-L2162","documentation":"ltx.NewEncoder failed when constructing the LTX encoder over the just-opened temp file. The temp file was opened successfully, so this typically indicates an invalid file descriptor state or an internal encoder initialization problem (the ltx package validates format parameters at construction). Replication for this transaction is aborted.","triggerScenarios":"The os.File passed to ltx.NewEncoder is invalid or already errored (e.g. the underlying file was closed or removed concurrently), or the ltx library rejects construction arguments.","commonSituations":"External tooling deleting/rotating files in the litestream staging directory mid-sync; running mismatched litestream/ltx library versions after an incomplete upgrade; extremely constrained environments where the fd became unusable.","solutions":["Upgrade litestream to a matching release so the ltx package versions are consistent (go.mod / binary rebuild).","Ensure nothing external touches files in the litestream data/staging directory while litestream is running.","Use `litestream reset` to clear corrupted local LTX state for the database, then restart litestream.","If reproducible, capture the underlying wrapped error and report it — NewEncoder failing on a fresh file usually indicates a bug."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Verify matched litestream/ltx versions before rollout:\n// go list -m all | grep ltx  && litestream version","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"new ltx encoder\") {\n    log.Printf(\"encoder init failed; check ltx library version and staging dir: %v\", err)\n    // escalate: likely bug or version mismatch, page on-call\n}","preventionTips":["Keep litestream binary and ltx dependency from the same release","Never let external tooling touch files in the litestream staging directory","Pin the litestream version in deployment manifests"],"tags":["ltx","encoder","replication"],"backgroundTag":"unsupported-operation","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"}