{"record":{"id":"cac7f79e4c794681","repo":"m1k1o/neko","slug":"session-already-exists","errorCode":null,"errorMessage":"session already exists","messagePattern":"session already exists","errorType":"error_code","errorClass":"ErrSessionAlreadyExists","httpStatus":null,"severity":"error","filePath":"server/pkg/types/session.go","lineNumber":11,"sourceCode":"package types\n\nimport (\n\t\"errors\"\n\t\"net/http\"\n\t\"time\"\n)\n\nvar (\n\tErrSessionNotFound         = errors.New(\"session not found\")\n\tErrSessionAlreadyExists    = errors.New(\"session already exists\")\n\tErrSessionAlreadyConnected = errors.New(\"session is already connected\")\n\tErrSessionLoginDisabled    = errors.New(\"session login disabled\")\n\tErrSessionLoginsLocked     = errors.New(\"session logins locked\")\n)\n\ntype Cursor struct {\n\tX int `json:\"x\"`\n\tY int `json:\"y\"`\n}\n\ntype SessionProfile struct {\n\tId      string\n\tToken   string\n\tProfile MemberProfile\n}\n\ntype SessionState struct {\n\tIsConnected bool `json:\"is_connected\"`","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/m1k1o/neko/blob/b0f01cedea68893e85a3fd852c0521238c285695/server/pkg/types/session.go#L1-L29","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Disconnect/Delete the existing session with that id first, then create the new one.","Look up the existing session via Get(id) and reuse it instead of creating a duplicate.","Enable/use merciful_reconnect handling so reconnects replace the old session.","Add client-side backoff so reconnect attempts don't race the server's session cleanup."],"exampleFix":"// before\n_, _, err := sessions.Create(id, profile) // ErrSessionAlreadyExists on reconnect\n// after\nif _, ok := sessions.Get(id); ok {\n    if err := sessions.Disconnect(id); err != nil {\n        return err\n    }\n}\n_, _, err := sessions.Create(id, profile)","handlingStrategy":"validation","validationCode":"// ensure no live session for the id before creating\nif _, ok := sessions.Get(id); ok {\n    _ = sessions.Disconnect(id)\n}","typeGuard":null,"tryCatchPattern":"_, _, err := sessions.Create(id, profile)\nif errors.Is(err, types.ErrSessionAlreadyExists) {\n    _ = sessions.Disconnect(id)\n    _, _, err = sessions.Create(id, profile)\n}\nreturn err","preventionTips":["Debounce rapid client reconnects.","Reuse existing sessions via Get instead of always creating.","Enable merciful_reconnect for seamless reconnect flows.","Uniquely key sessions per member+connection to avoid collisions."],"tags":["session","concurrency","reconnect","go"],"backgroundTag":"duplicate-resource-conflict","analyzedSha":"b0f01cedea68893e85a3fd852c0521238c285695","analyzedAt":"2026-09-01T10:35:56.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}