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

  1. Log the wrapped cause (%v) and validate DBHOST/DBPORT/DBUSER/DBPASS env values before SetConfig
  2. Confirm the gdb version's Config/ConfigGroup API usage matches the vendored GoFrame version
  3. Ensure InitDatabase runs only once (use sync.Once) to avoid config re-registration issues
  4. 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

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


AI-assisted analysis of Billionmail/BillionMail@fc36c76c05 (2026-09-05). Data as JSON: /api/errors/383a83b0b22a1ab7. Report an issue: GitHub.