AdguardTeam/AdGuardHome · error

length of the data is less than expected: got %d

Error message

length of the data is less than expected: got %d

What it means

bboltDecode rejects a stored session record whose binary length is shorter than the minimum encoding (4-byte expire + 2-byte name length). It means the value stored in the sessions bucket is not a session serialized by bboltEncode — data corruption or a foreign/incompatible writer.

Source

Thrown at internal/aghuser/sessionstorage.go:285

// bboltBucketSessions is the name of the bucket storing web user sessions in
// the bbolt database.
const bboltBucketSessions = "sessions-2"

const (
	// bboltSessionExpireLen is the length of the expire field in the binary
	// entry stored in bbolt.
	bboltSessionExpireLen = 4

	// bboltSessionNameLen is the length of the name field in the binary entry
	// stored in bbolt.
	bboltSessionNameLen = 2
)

// bboltDecode deserializes decodes a binary data into a session.
func bboltDecode(data []byte) (s *Session, err error) {
	if len(data) < bboltSessionExpireLen+bboltSessionNameLen {
		return nil, fmt.Errorf("length of the data is less than expected: got %d", len(data))
	}

	expireData := data[:bboltSessionExpireLen]
	nameLenData := data[bboltSessionExpireLen : bboltSessionExpireLen+bboltSessionNameLen]
	nameData := data[bboltSessionExpireLen+bboltSessionNameLen:]

	nameLen := binary.BigEndian.Uint16(nameLenData)
	if len(nameData) != int(nameLen) {
		return nil, fmt.Errorf("login: expected length %d, got %d", nameLen, len(nameData))
	}

	expire := binary.BigEndian.Uint32(expireData)

	return &Session{
		Expire:    time.Unix(int64(expire), 0),
		UserLogin: Login(nameData),
	}, nil
}

View on GitHub (pinned to b41aefbe51)

Solutions

  1. Delete the sessions database file (sessions are non-critical) and restart
  2. Check for version mismatch: upgrade path must be forward-only; redeploy the matching version
  3. Verify db integrity with bbolt check / restore from backup

Example fix

rm /var/lib/adguardhome/sessions.db # sessions are recreated on next login
Defensive patterns

Strategy: fallback

Type guard

func isValidSessionData(b []byte) bool { return len(b) >= 6 }

Try / catch

// on decode-length errors, delete the offending session file/db and let users re-login
if err != nil && strings.Contains(err.Error(), "length of the data is less than expected") { os.Remove(dbPath) }

Prevention

When it happens

Trigger: processSessions / FindByToken decode a bucket value that is 0–5 bytes long; caused by truncated writes, manual tampering with the db, or an older format written by a previous version.

Common situations: Downgrade to an older AdGuard Home after a newer version changed the session encoding; editing session.db with external bbolt tooling; power loss truncating the file.

Related errors


AI-assisted analysis of AdguardTeam/AdGuardHome@b41aefbe51 (2026-08-27). Data as JSON: /api/errors/c31dea3037e1a2db. Report an issue: GitHub.