{"record":{"id":"92d50623f8623ed3","repo":"AdguardTeam/AdGuardHome","slug":"loading-db-w","errorCode":null,"errorMessage":"loading db: %w","messagePattern":"loading db: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/dhcpd/dhcpd.go","lineNumber":154,"sourceCode":"\ts.conf.Conf4 = conf.Conf4\n\ts.conf.Conf6 = conf.Conf6\n\n\tif s.conf.Enabled && !v4Enabled && !v6Enabled {\n\t\treturn nil, fmt.Errorf(\"neither dhcpv4 nor dhcpv6 srv is configured\")\n\t}\n\n\t// Migrate leases db if needed.\n\terr = migrateDB(conf)\n\tif err != nil {\n\t\t// Don't wrap the error since it's informative enough as is.\n\t\treturn nil, err\n\t}\n\n\t// Don't delay database loading until the DHCP server is started,\n\t// because we need static leases functionality available beforehand.\n\terr = s.dbLoad()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"loading db: %w\", err)\n\t}\n\n\treturn s, nil\n}\n\n// setServers updates DHCPv4 and DHCPv6 servers created from the provided\n// configuration conf.  It returns the status of both the DHCPv4 and the DHCPv6\n// servers, which is always false for corresponding server on any error.\nfunc (s *server) setServers(\n\tctx context.Context,\n\tconf *ServerConfig,\n) (v4Enabled, v6Enabled bool, err error) {\n\tv4conf := conf.Conf4\n\tv4conf.Logger = s.conf.Logger.With(\"ip_version\", \"4\")\n\tv4conf.InterfaceName = s.conf.InterfaceName\n\tv4conf.notify = s.onNotify\n\tv4conf.Enabled = s.conf.Enabled && v4conf.RangeStart.IsValid()\n","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/AdguardTeam/AdGuardHome/blob/b41aefbe51c8dde65e2c50f093996afa0502edf9/internal/dhcpd/dhcpd.go#L136-L172","documentation":"The DHCP server failed during initial database loading (dbLoad) at Create time; the message wraps any of the read/decode/lease-conversion/reset errors (errors 109–112). It prevents the server from starting with an unusable lease DB.","triggerScenarios":"Calling Create when the leases file is unreadable, invalid JSON, contains bad MAC/RFC3339 values, or lease data incompatible with current config.","commonSituations":"First start after a crash corrupted leases.json; permission problems in the data dir; subnet/range changes invalidating stored leases.","solutions":["Read the wrapped error to identify the specific stage (read/decode/parse/reset)","Fix or delete the offending leases file (dynamic leases are re-acquired automatically)","Ensure the service user has read/write access to the data directory"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// pre-check DB readability/validity\nif data, err := os.ReadFile(dbPath); err == nil && !json.Valid(data) { /* move aside */ }","typeGuard":null,"tryCatchPattern":"s, err := dhcpd.Create(ctx, conf)\nif err != nil {\n    if strings.Contains(err.Error(), \"loading db\") { /* recover/rotate leases file, retry once */ }\n    return err\n}","preventionTips":["Keep the data dir writable and backed up","Treat wrapped 'loading db' errors as recoverable by resetting leases"],"tags":["dhcp","startup","leases","persistence"],"backgroundTag":"dhcp-database-load-failed","analyzedSha":"b41aefbe51c8dde65e2c50f093996afa0502edf9","analyzedAt":"2026-08-27T04:57:55.097Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}