beego/beego · error
SessionInit First
Error message
SessionInit First
What it means
The ssdb session Provider (server/web/session/ssdb/sess_ssdb.go:30) only learns its Host and Port when SessionInit parses the JSON provider config. connectInit returns 'SessionInit First' when Host or Port is still zero: the connection was attempted before initialization, or the config string never supplied those fields.
Source
Thrown at server/web/session/ssdb/sess_ssdb.go:30
"github.com/ssdb/gossdb/ssdb"
"github.com/beego/beego/v2/server/web/session"
)
var ssdbProvider = &Provider{}
// Provider holds ssdb client and configs
type Provider struct {
client *ssdb.Client
Host string `json:"host"`
Port int `json:"port"`
maxLifetime int64
}
func (p *Provider) connectInit() error {
var err error
if p.Host == "" || p.Port == 0 {
return errors.New("SessionInit First")
}
p.client, err = ssdb.Connect(p.Host, p.Port)
return err
}
// SessionInit init the ssdb with the config
func (p *Provider) SessionInit(ctx context.Context, maxLifetime int64, cfg string) error {
p.maxLifetime = maxLifetime
cfg = strings.TrimSpace(cfg)
var err error
// we think this is v2.0, using json to init the session
if strings.HasPrefix(cfg, "{") {
err = json.Unmarshal([]byte(cfg), p)
} else {
err = p.initOldStyle(cfg)
}
if err != nil {View on GitHub (pinned to 939cfde380)
Solutions
- Set the full JSON provider config: SessionProvider = ssdb and SessionProviderConfig = {"host":"127.0.0.1","port":8888}
- Confirm the config string is valid JSON and correctly quoted in app.conf
- Use the provider only through NewManager so SessionInit always precedes any connection attempt
Example fix
# app.conf - before
sessionprovider = ssdb
sessionproviderconfig = 127.0.0.1:8888
# app.conf - after
sessionprovider = ssdb
sessionproviderconfig = {"host":"127.0.0.1","port":8888} Defensive patterns
Strategy: validation
Validate before calling
type ssdbCfg struct {
Host string `json:"host"`
Port int `json:"port"`
}
var c ssdbCfg
if err := json.Unmarshal([]byte(providerConfig), &c); err != nil || c.Host == "" || c.Port == 0 {
log.Fatalf("ssdb session config must be JSON like {\"host\":\"127.0.0.1\",\"port\":8888}, got: %s", providerConfig)
} Type guard
func hasSSDBEndpoints(cfg string) bool {
var c struct {
Host string `json:"host"`
Port int `json:"port"`
}
return json.Unmarshal([]byte(cfg), &c) == nil && c.Host != "" && c.Port != 0
} Prevention
- Keep the ssdb provider config as strict JSON with both host and port
- Prefer constructing the Manager via NewManager so SessionInit always runs first
- Add startup config validation for third-party session providers
When it happens
Trigger: SessionProviderConfig that is not JSON like {"host":"127.0.0.1","port":8888}; a config string missing host or port keys; calling the provider's read/destroy methods directly before NewManager ran SessionInit.
Common situations: Typos or quoting mistakes in app.conf's session provider config; migrating from a 'host:port' style config to the JSON form; deploying the ssdb provider without verifying the config reached SessionInit.
Related errors
- Decode: expired timestamp
- SessionNameInHTTPHeader is empty
- SessionNameInHTTPHeader (${SessionNameInHTTPHeader}) has the
- unsupported operation
- the key is not found
AI-assisted analysis of beego/beego@939cfde380 (2026-08-15).
Data as JSON: /api/errors/6897b91d4186d91b.
Report an issue: GitHub.