Billionmail/BillionMail · critical
Set database configuration failed: %v
Error message
Set database configuration failed: %v
What it means
After building the gdb.Config with host/port/user/password, gdb.SetConfig is called; a non-nil error there means GoFrame rejected the configuration group and database initialization stops with this wrapped message.
Source
Thrown at core/internal/service/database_initialization/database_initialization.go:40
// Setting database configuration
err = gdb.SetConfig(gdb.Config{
"default": gdb.ConfigGroup{
gdb.ConfigNode{
// Debug: true,
Host: public.AbsPath(consts.POSTGRESQL_SOCK),
User: "billionmail",
Pass: dbPass,
Name: "billionmail",
Type: "pgsql",
Role: "master",
MaxOpenConnCount: 100,
},
},
})
if err != nil {
return fmt.Errorf("Set database configuration failed: %v", err)
}
// Testing database connection until successful
connectionOK := false
for i := 0; i < 10; i++ {
_, err = g.DB().Exec(context.Background(), "SELECT 1")
if err != nil {
// Wait for 5 seconds before retrying
g.Log().Debug(context.Background(), "Database connection failed, retrying in 5 seconds...")
time.Sleep(time.Second * 5)
continue
}
connectionOK = true
g.Log().Debug(context.Background(), "Database connection successful")
break
}View on GitHub (pinned to fc36c76c05)
Solutions
- Log the wrapped cause (%v) and validate DBHOST/DBPORT/DBUSER/DBPASS env values before SetConfig
- Confirm the gdb version's Config/ConfigGroup API usage matches the vendored GoFrame version
- Ensure InitDatabase runs only once (use sync.Once) to avoid config re-registration issues
- Fall back to explicit default values when env vars are empty
Example fix
// before
host := public.DockerEnv("DBHOST") // may be empty
// after
if host == "" { host = "postgres" } // default node Defensive patterns
Strategy: validation
Validate before calling
if dbHost == "" || dbPort == "" || dbUser == "" || dbPass == "" {
return errors.New("database env vars incomplete before SetConfig")
} Try / catch
if err := database_initialization.InitDatabase(); err != nil {
if strings.Contains(err.Error(), "Set database configuration") {
log.Fatalf("invalid gdb config: %v", err)
}
} Prevention
- Validate all DB env values before building gdb.Config
- Call InitDatabase once via sync.Once
- Keep GoFrame version pinned and reviewed on upgrade
- Provide defaults for optional config fields
When it happens
Trigger: Passing a malformed config to gdb.SetConfig — e.g. empty default group, invalid node fields, or a concurrent reconfiguration conflict in the GoFrame driver.
Common situations: Corrupted env-derived values (DBHOST/DBPORT/DBUSER empty) producing an invalid config node; upgrading GoFrame where Config semantics changed; calling InitDatabase twice with conflicting setups.
Related errors
- Failed to add exception recipient: %w
- Failed to remove exception recipient: %w
- Failed to get exception recipient: %w
- Failed to query existing abnormal recipients: %w
- Failed to update abnormal recipient: %w
AI-assisted analysis of Billionmail/BillionMail@fc36c76c05 (2026-09-05).
Data as JSON: /api/errors/383a83b0b22a1ab7.
Report an issue: GitHub.