{"record":{"id":"229f3d23299f2599","repo":"benbjohnson/litestream","slug":"extract-timestamp-from-ltx-header-w","errorCode":null,"errorMessage":"extract timestamp from LTX header: %w","messagePattern":"extract timestamp from LTX header: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"abs/replica_client.go","lineNumber":231,"sourceCode":"\treturn newLTXFileIterator(ctx, c, level, seek), nil\n}\n\n// WriteLTXFile writes an LTX file to remote storage.\nfunc (c *ReplicaClient) WriteLTXFile(ctx context.Context, level int, minTXID, maxTXID ltx.TXID, rd io.Reader) (info *ltx.FileInfo, err error) {\n\tif err := c.Init(ctx); err != nil {\n\t\treturn nil, err\n\t}\n\n\tkey := litestream.LTXFilePath(c.Path, level, minTXID, maxTXID)\n\n\t// Use TeeReader to peek at LTX header while preserving data for upload\n\tvar buf bytes.Buffer\n\tteeReader := io.TeeReader(rd, &buf)\n\n\t// Extract timestamp from LTX header\n\thdr, _, err := ltx.PeekHeader(teeReader)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"extract timestamp from LTX header: %w\", err)\n\t}\n\ttimestamp := time.UnixMilli(hdr.Timestamp).UTC()\n\n\t// Combine buffered data with rest of reader\n\trc := internal.NewReadCounter(io.MultiReader(&buf, rd))\n\n\t// Upload blob with proper content type, access tier, and metadata\n\t// Azure metadata keys cannot contain hyphens, so use litestreamtimestamp\n\t_, err = c.client.UploadStream(ctx, c.Bucket, key, rc, &azblob.UploadStreamOptions{\n\t\tHTTPHeaders: &blob.HTTPHeaders{\n\t\t\tBlobContentType: to.Ptr(\"application/octet-stream\"),\n\t\t},\n\t\tAccessTier: to.Ptr(blob.AccessTierHot), // Use Hot tier as default\n\t\tMetadata: map[string]*string{\n\t\t\tMetadataKeyTimestamp: to.Ptr(timestamp.Format(time.RFC3339Nano)),\n\t\t},\n\t})\n\tif err != nil {","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/abs/replica_client.go#L213-L249","documentation":"abs.WriteLTXFile failed to read the LTX header from the incoming stream via ltx.PeekHeader before uploading. It fires when the stream is shorter than an LTX header (ltx.HeaderSize) or contains a corrupt/invalid magic number, meaning the data being replicated is not a valid LTX file.","triggerScenarios":"Thrown at abs/replica_client.go:231 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check upstream producer of the LTX stream for truncation or corruption","Verify the local shadow WAL/LTX files are not corrupted (litestream ltx to inspect)","If the local LTX state is corrupted, run 'litestream reset' to clear it and re-sync"],"exampleFix":null,"handlingStrategy":"validation","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"}