mattermost-community/focalboard · error
unable to create session
Error message
unable to create session
What it means
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.
Source
Thrown at server/app/auth.go:125
a.logger.Debug("Invalid password for user", mlog.String("userID", user.ID))
return "", errors.New("invalid username or password")
}
authService := user.AuthService
if authService == "" {
authService = "native"
}
session := model.Session{
ID: utils.NewID(utils.IDTypeSession),
Token: utils.NewID(utils.IDTypeToken),
UserID: user.ID,
AuthService: authService,
Props: map[string]interface{}{},
}
err := a.store.CreateSession(&session)
if err != nil {
return "", errors.Wrap(err, "unable to create session")
}
a.metrics.IncrementLoginCount(1)
// TODO: MFA verification
return session.Token, nil
}
// Logout invalidates the user session.
func (a *App) Logout(sessionID string) error {
err := a.store.DeleteSession(sessionID)
if err != nil {
return errors.Wrap(err, "unable to delete the session")
}
a.metrics.IncrementLogoutCount(1)
return nilView on GitHub (pinned to a84bbb65e3)
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
Example fix
// before
// ignoring wrapped cause makes diagnosis hard
return err
// after
if err != nil {
log.Errorf("create session failed: %v", errors.Cause(err))
if isRetryable(errors.Cause(err)) {
time.Sleep(500 * time.Millisecond)
return a.Login(username, email, password, mfaToken) // retry once
}
return err
} Defensive patterns
Strategy: retry
Validate before calling
// Confirm store writability before login
if err := store.Ping(); err != nil {
return fmt.Errorf("store not ready for sessions: %w", err)
} Type guard
func isRetryableStoreErr(err error) bool {
c := errors.Cause(err)
return errors.Is(c, sql.ErrConnDone) || errors.Is(c, driver.ErrBadConn)
} Try / catch
token, err := app.Login(username, email, password, "")
if err != nil && strings.Contains(err.Error(), "unable to create session") {
time.Sleep(backoff)
token, err = app.Login(username, email, password, "") // retry once
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Database disk full; sessions table missing/corrupted after partial migration; DB connection pool exhausted; store write permissions or replication issues.
Related errors
- insertBoard error occurred while fetching existing board %s:
- unable to delete the session
- ErrorId.NotLoggedIn
- card limit value is invalid
- database type is unsupported
AI-assisted analysis of mattermost-community/focalboard@a84bbb65e3 (2026-08-30).
Data as JSON: /api/errors/7e1f0eb90cffd0b9.
Report an issue: GitHub.