benbjohnson/litestream · error

failed to discard offset bytes: %w

Error message

failed to discard offset bytes: %w

What it means

Wraps io.CopyN failure while discarding the leading 'offset' bytes of a fetched NATS object in OpenLTXFile. Fires when a non-zero read offset was requested (partial LTX read) but the underlying stream ends or errors before the offset is reached.

Source

Thrown at nats/replica_client.go:377

	objectPath := c.ltxPath(level, minTXID, maxTXID)

	objectResult, err := c.objectStore.Get(ctx, objectPath)
	if err != nil {
		if isNotFoundError(err) {
			return nil, os.ErrNotExist
		}
		return nil, fmt.Errorf("failed to get object %s: %w", objectPath, err)
	}

	// Record metrics
	internal.OperationTotalCounterVec.WithLabelValues(ReplicaClientType, "GET").Inc()
	// Note: We can't get the size from NATS object reader directly, so we skip bytes counter

	// If offset is non-zero then discard the beginning bytes.
	if offset > 0 {
		if _, err := io.CopyN(io.Discard, objectResult, offset); err != nil {
			objectResult.Close()
			return nil, fmt.Errorf("failed to discard offset bytes: %w", err)
		}
	}

	// If size is non-zero then limit the reader to the size.
	if size > 0 {
		return internal.LimitReadCloser(objectResult, size), nil
	}

	return objectResult, nil
}

// WriteLTXFile writes an LTX file to the replica.
func (c *ReplicaClient) WriteLTXFile(ctx context.Context, level int, minTXID, maxTXID ltx.TXID, r io.Reader) (*ltx.FileInfo, error) {
	if err := c.Init(ctx); err != nil {
		return nil, err
	}

	objectPath := c.ltxPath(level, minTXID, maxTXID)

View on GitHub (pinned to 4ed7a308f6)

Solutions

  1. Verify the requested offset/size match the real object size (corruption or truncated object)
  2. Re-upload the affected LTX file if the object store copy is truncated
  3. Inspect the wrapped error for read failures
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at nats/replica_client.go:377 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of benbjohnson/litestream@4ed7a308f6 (2026-09-06). Data as JSON: /api/errors/66aba1e5ca1a8cba. Report an issue: GitHub.