AdguardTeam/AdGuardHome · error
putting unit to database: %w
Error message
putting unit to database: %w
What it means
After encoding, putting the unit's bytes into the bbolt bucket failed; wrapped as 'putting unit to database'.
Source
Thrown at internal/stats/unit.go:359
// flushUnitToDB puts udb to the database at id.
func (s *StatsCtx) flushUnitToDB(udb *unitDB, tx *bbolt.Tx, id uint32) (err error) {
s.logger.Debug("flushing unit", "id", id, "req_num", udb.NTotal)
bkt, err := tx.CreateBucketIfNotExists(idToUnitName(id))
if err != nil {
return fmt.Errorf("creating bucket: %w", err)
}
buf := &bytes.Buffer{}
err = gob.NewEncoder(buf).Encode(udb)
if err != nil {
return fmt.Errorf("encoding unit: %w", err)
}
err = bkt.Put([]byte{0}, buf.Bytes())
if err != nil {
return fmt.Errorf("putting unit to database: %w", err)
}
return nil
}
func convertTopSlice(a []countPair) (m []map[string]uint64) {
m = make([]map[string]uint64, 0, len(a))
for _, it := range a {
m = append(m, map[string]uint64{it.Name: it.Count})
}
return m
}
// pairsGetter is a signature for topsCollector argument.
type pairsGetter func(u *unitDB) (pairs []countPair)
// topsCollector collects statistics about highest values from the given *unitDBView on GitHub (pinned to b41aefbe51)
Solutions
- Reduce the stats data volume or increase available disk/space for the transaction
- Verify no concurrent Close/reset while flushing
- Batch or trim oversized units before flush
Defensive patterns
Strategy: try-catch
Try / catch
if err := s.Close(); err != nil { log.Printf("persist failed: %v", err) } Prevention
- Bound per-unit data size
- Monitor disk space; enlarge volume for large deployments
When it happens
Trigger: bkt.Put failing due to a read-only transaction, transaction too large (exceeds bbolt/disk limits), or the DB being closed/corrupted during flush.
Common situations: Very large stats units (huge transaction), disk full, or races between flush and Close/clear.
Related errors
- opening database: %w
- opening a transaction: %w
- opening transaction: %w
- closing database: %w
- creating bucket: %w
AI-assisted analysis of AdguardTeam/AdGuardHome@b41aefbe51 (2026-08-27).
Data as JSON: /api/errors/6c9349fe77fc6430.
Report an issue: GitHub.