m1k1o/neko · error · ErrSessionAlreadyExists

session already exists

Error message

session already exists

What it means

ErrSessionAlreadyExists is a sentinel error in the neko types package indicating that SessionManager.Create was called with an id for which a session already exists. The manager refuses to create a duplicate session with the same identifier.

Source

Thrown at server/pkg/types/session.go:11

package types

import (
	"errors"
	"net/http"
	"time"
)

var (
	ErrSessionNotFound         = errors.New("session not found")
	ErrSessionAlreadyExists    = errors.New("session already exists")
	ErrSessionAlreadyConnected = errors.New("session is already connected")
	ErrSessionLoginDisabled    = errors.New("session login disabled")
	ErrSessionLoginsLocked     = errors.New("session logins locked")
)

type Cursor struct {
	X int `json:"x"`
	Y int `json:"y"`
}

type SessionProfile struct {
	Id      string
	Token   string
	Profile MemberProfile
}

type SessionState struct {
	IsConnected bool `json:"is_connected"`

View on GitHub (pinned to b0f01cedea)

Solutions

  1. Disconnect/Delete the existing session with that id first, then create the new one.
  2. Look up the existing session via Get(id) and reuse it instead of creating a duplicate.
  3. Enable/use merciful_reconnect handling so reconnects replace the old session.
  4. Add client-side backoff so reconnect attempts don't race the server's session cleanup.

Example fix

// before
_, _, err := sessions.Create(id, profile) // ErrSessionAlreadyExists on reconnect
// after
if _, ok := sessions.Get(id); ok {
    if err := sessions.Disconnect(id); err != nil {
        return err
    }
}
_, _, err := sessions.Create(id, profile)
Defensive patterns

Strategy: validation

Validate before calling

// ensure no live session for the id before creating
if _, ok := sessions.Get(id); ok {
    _ = sessions.Disconnect(id)
}

Try / catch

_, _, err := sessions.Create(id, profile)
if errors.Is(err, types.ErrSessionAlreadyExists) {
    _ = sessions.Disconnect(id)
    _, _, err = sessions.Create(id, profile)
}
return err

Prevention

When it happens

Trigger: Calling Create(id, profile) when a session with that id is still registered (e.g. a client reconnecting with the same member id before the old session was deleted).

Common situations: Rapid reconnects (page refresh, flaky network) where the old session hasn't timed out yet; merciful-reconnect flows racing session creation; duplicate login from the same account without disconnecting the prior session.

Related errors


AI-assisted analysis of m1k1o/neko@b0f01cedea (2026-09-01). Data as JSON: /api/errors/cac7f79e4c794681. Report an issue: GitHub.