{"record":{"id":"7e1f0eb90cffd0b9","repo":"mattermost-community/focalboard","slug":"unable-to-create-session","errorCode":null,"errorMessage":"unable to create session","messagePattern":"unable to create session","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/app/auth.go","lineNumber":125,"sourceCode":"\t\ta.logger.Debug(\"Invalid password for user\", mlog.String(\"userID\", user.ID))\n\t\treturn \"\", errors.New(\"invalid username or password\")\n\t}\n\n\tauthService := user.AuthService\n\tif authService == \"\" {\n\t\tauthService = \"native\"\n\t}\n\n\tsession := model.Session{\n\t\tID:          utils.NewID(utils.IDTypeSession),\n\t\tToken:       utils.NewID(utils.IDTypeToken),\n\t\tUserID:      user.ID,\n\t\tAuthService: authService,\n\t\tProps:       map[string]interface{}{},\n\t}\n\terr := a.store.CreateSession(&session)\n\tif err != nil {\n\t\treturn \"\", errors.Wrap(err, \"unable to create session\")\n\t}\n\n\ta.metrics.IncrementLoginCount(1)\n\n\t// TODO: MFA verification\n\treturn session.Token, nil\n}\n\n// Logout invalidates the user session.\nfunc (a *App) Logout(sessionID string) error {\n\terr := a.store.DeleteSession(sessionID)\n\tif err != nil {\n\t\treturn errors.Wrap(err, \"unable to delete the session\")\n\t}\n\n\ta.metrics.IncrementLogoutCount(1)\n\n\treturn nil","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/mattermost-community/focalboard/blob/a84bbb65e32edf972856b329417096ac413518e9/server/app/auth.go#L107-L143","documentation":"Login wraps an error from store.CreateSession as 'unable to create session'. After user/password validation succeeds, the app persists a new Session (ID, token, userID) to the store; if that write fails, login cannot issue a token and this wrapped error is returned. It indicates a storage-layer problem, not an authentication problem.","triggerScenarios":"App.Login with valid credentials where a.store.CreateSession returns an error: DB write failure, constraint violation on the sessions table, store closed/locked, or storage backend outage.","commonSituations":"Database disk full; sessions table missing/corrupted after partial migration; DB connection pool exhausted; store write permissions or replication issues.","solutions":["Inspect the wrapped cause for the store's underlying write error","Check DB health: disk space, connection limits, sessions table exists and is migrated","Retry the login once the storage backend recovers","If a corrupted/partial session row conflicts, delete the stale session row and retry"],"exampleFix":"// before\n// ignoring wrapped cause makes diagnosis hard\nreturn err\n// after\nif err != nil {\n    log.Errorf(\"create session failed: %v\", errors.Cause(err))\n    if isRetryable(errors.Cause(err)) {\n        time.Sleep(500 * time.Millisecond)\n        return a.Login(username, email, password, mfaToken) // retry once\n    }\n    return err\n}","handlingStrategy":"retry","validationCode":"// Confirm store writability before login\nif err := store.Ping(); err != nil {\n    return fmt.Errorf(\"store not ready for sessions: %w\", err)\n}","typeGuard":"func isRetryableStoreErr(err error) bool {\n    c := errors.Cause(err)\n    return errors.Is(c, sql.ErrConnDone) || errors.Is(c, driver.ErrBadConn)\n}","tryCatchPattern":"token, err := app.Login(username, email, password, \"\")\nif err != nil && strings.Contains(err.Error(), \"unable to create session\") {\n    time.Sleep(backoff)\n    token, err = app.Login(username, email, password, \"\") // retry once\n}","preventionTips":["Monitor DB disk space and connection pool saturation","Keep sessions table migrations up to date","Use idempotent session creation (fixed session ID) when retrying","Alert on CreateSession error rates"],"tags":["session","database","storage"],"backgroundTag":"session-persistence-failure","analyzedSha":"a84bbb65e32edf972856b329417096ac413518e9","analyzedAt":"2026-08-30T09:22:20.720Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}