{"record":{"id":"6897b91d4186d91b","repo":"beego/beego","slug":"sessioninit-first","errorCode":null,"errorMessage":"SessionInit First","messagePattern":"SessionInit First","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/web/session/ssdb/sess_ssdb.go","lineNumber":30,"sourceCode":"\t\"github.com/ssdb/gossdb/ssdb\"\n\n\t\"github.com/beego/beego/v2/server/web/session\"\n)\n\nvar ssdbProvider = &Provider{}\n\n// Provider holds ssdb client and configs\ntype Provider struct {\n\tclient      *ssdb.Client\n\tHost        string `json:\"host\"`\n\tPort        int    `json:\"port\"`\n\tmaxLifetime int64\n}\n\nfunc (p *Provider) connectInit() error {\n\tvar err error\n\tif p.Host == \"\" || p.Port == 0 {\n\t\treturn errors.New(\"SessionInit First\")\n\t}\n\tp.client, err = ssdb.Connect(p.Host, p.Port)\n\treturn err\n}\n\n// SessionInit init the ssdb with the config\nfunc (p *Provider) SessionInit(ctx context.Context, maxLifetime int64, cfg string) error {\n\tp.maxLifetime = maxLifetime\n\n\tcfg = strings.TrimSpace(cfg)\n\tvar err error\n\t// we think this is v2.0, using json to init the session\n\tif strings.HasPrefix(cfg, \"{\") {\n\t\terr = json.Unmarshal([]byte(cfg), p)\n\t} else {\n\t\terr = p.initOldStyle(cfg)\n\t}\n\tif err != nil {","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/beego/beego/blob/939cfde380bb9f15844ad633b84f037f7da21584/server/web/session/ssdb/sess_ssdb.go#L12-L48","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# app.conf - before\nsessionprovider = ssdb\nsessionproviderconfig = 127.0.0.1:8888\n\n# app.conf - after\nsessionprovider = ssdb\nsessionproviderconfig = {\"host\":\"127.0.0.1\",\"port\":8888}","handlingStrategy":"validation","validationCode":"type ssdbCfg struct {\n    Host string `json:\"host\"`\n    Port int    `json:\"port\"`\n}\nvar c ssdbCfg\nif err := json.Unmarshal([]byte(providerConfig), &c); err != nil || c.Host == \"\" || c.Port == 0 {\n    log.Fatalf(\"ssdb session config must be JSON like {\\\"host\\\":\\\"127.0.0.1\\\",\\\"port\\\":8888}, got: %s\", providerConfig)\n}","typeGuard":"func hasSSDBEndpoints(cfg string) bool {\n    var c struct {\n        Host string `json:\"host\"`\n        Port int    `json:\"port\"`\n    }\n    return json.Unmarshal([]byte(cfg), &c) == nil && c.Host != \"\" && c.Port != 0\n}","tryCatchPattern":null,"preventionTips":["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"],"tags":["session","ssdb","config","database"],"backgroundTag":null,"analyzedSha":"939cfde380bb9f15844ad633b84f037f7da21584","analyzedAt":"2026-08-15T17:22:06.535Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}