containerd/containerd · error
failed encoding size = %v
Error message
failed encoding size = %v
What it means
encodeSize in the bolt snapshotter metastore encodes an int64 size as a varint. It errors only if the encoded byte slice is empty after binary.PutVarint, which in practice never happens for any int64 value — the guard is defensive. If seen, it indicates a corrupted or misused metastore code path.
Source
Thrown at core/snapshots/storage/bolt.go:615
if err != nil {
return err
}
if err := bkt.Put(v.key, e); err != nil {
return err
}
}
return nil
}
func encodeSize(size int64) ([]byte, error) {
var (
buf [binary.MaxVarintLen64]byte
sizeEncoded = buf[:]
)
sizeEncoded = sizeEncoded[:binary.PutVarint(sizeEncoded, size)]
if len(sizeEncoded) == 0 {
return nil, fmt.Errorf("failed encoding size = %v", size)
}
return sizeEncoded, nil
}
func encodeID(id uint64) ([]byte, error) {
var (
buf [binary.MaxVarintLen64]byte
idEncoded = buf[:]
)
idEncoded = idEncoded[:binary.PutUvarint(idEncoded, id)]
if len(idEncoded) == 0 {
return nil, fmt.Errorf("failed encoding id = %v", id)
}
return idEncoded, nil
}
func adaptSnapshot(info snapshots.Info) filters.Adaptor {View on GitHub (pinned to 4246446a2b)
Solutions
- Report/inspect the size value being passed to putUsage; a non-int64 (e.g. float cast) caller bug is the only plausible cause
- Update containerd to a current patch release to rule out an old defect
- Rebuild/inspect the bolt database file (containerd metadata snapshot bolt db) for corruption
Defensive patterns
Strategy: try-catch
Validate before calling
if size < math.MinInt64 || size > math.MaxInt64 {
return fmt.Errorf("size out of int64 range: %v", size)
} Try / catch
encoded, err := encodeSize(size)
if err != nil {
log.WithError(err).Errorf("snapshot usage size encoding failed for size=%d", size)
return err
} Prevention
- Pass only int64 values into putUsage
- Treat this as a code-level bug and report it upstream rather than working around it
When it happens
Trigger: putUsage calls encodeSize with a size value when storing snapshot usage; the error fires if binary.PutVarint returns 0 bytes written, which cannot occur with binary.MaxVarintLen64 capacity for valid int64 input.
Common situations: Essentially unreachable in practice; would only appear if the bolt snapshotter metastore code was modified or if instrumentation/wrapping changed PutVarint behavior.
Related errors
- failed encoding id = %v
- media type not found
- runtime not found in index
- no snapshotter set for container
- rootfs snapshot not created for container
AI-assisted analysis of containerd/containerd@4246446a2b (2026-09-02).
Data as JSON: /api/errors/066b289f15ed77a2.
Report an issue: GitHub.