{"record":{"id":"13ff200b0a6b38f7","repo":"TechnitiumSoftware/DnsServer","slug":"error-while-creating-session-please-try-again","errorCode":null,"errorMessage":"Error while creating session. Please try again.","messagePattern":"Error while creating session\\. Please try again\\.","errorType":"exception","errorClass":"DnsWebServiceException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/Auth/AuthManager.cs","lineNumber":1166,"sourceCode":"            {\n                if (session.Value.User.Equals(user) && !session.Value.HasExpired())\n                    userSessions.Add(session.Value);\n            }\n\n            return userSessions;\n        }\n\n        public async Task<UserSession> CreateSessionAsync(UserSessionType type, string tokenName, string username, string password, string totp, IPAddress remoteAddress, string userAgent)\n        {\n            User user = await AuthenticateUserAsync(username, password, totp, remoteAddress);\n\n            if (type == UserSessionType.ClusterApiToken)\n                throw new InvalidOperationException();\n\n            UserSession session = new UserSession(type, tokenName, user, remoteAddress, userAgent);\n\n            if (!_sessions.TryAdd(session.Token, session))\n                throw new DnsWebServiceException(\"Error while creating session. Please try again.\");\n\n            user.LoggedInFrom(remoteAddress);\n\n            return session;\n        }\n\n        public UserSession CreateSession(UserSessionType type, string tokenName, string username, IPAddress remoteAddress, string userAgent)\n        {\n            User user = GetUser(username);\n            if (user is null)\n                throw new DnsWebServiceException(\"No such user exists: \" + username);\n\n            return CreateSession(type, tokenName, user, remoteAddress, userAgent);\n        }\n\n        public UserSession CreateSession(UserSessionType type, string tokenName, User user, IPAddress remoteAddress, string userAgent)\n        {\n            if (user.Disabled)","sourceCodeStart":1148,"sourceCodeEnd":1184,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Auth/AuthManager.cs#L1148-L1184","documentation":"Thrown as DnsWebServiceException from CreateSessionAsync when _sessions.TryAdd(session.Token, session) returns false, meaning a session token already exists with the same value. Tokens are generated UUIDs, so a collision is astronomically unlikely; the message explicitly invites a retry. Returned over the API as HTTP 200 with status 'error'.","triggerScenarios":"POST /api/user/login (or token creation) where the freshly generated session token collides with an existing token in _sessions; also thrown if type is UserSessionType.ClusterApiToken (that throws InvalidOperationException, a different path).","commonSituations":"Effectively never in practice unless the RNG/UUID source is broken or seeded identically across nodes; a retry resolves it.","solutions":["Retry the login/token creation once; a new token will be generated.","If it recurs, investigate the session token generator / UUID uniqueness.","As a last resort, restarting the service clears in-memory sessions."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// No meaningful pre-check: token collisions are random and not predictable.","typeGuard":null,"tryCatchPattern":"async Task<SessionInfo> LoginWithRetry(string user, string pass, string totp)\n{\n    try { return await client.LoginAsync(user, pass, totp); }\n    catch (HttpApiClientException ex) when (ex.Message.Contains(\"Error while creating session\"))\n    { return await client.LoginAsync(user, pass, totp); }\n}","preventionTips":["Treat 'Error while creating session' as transient and retry once.","If it recurs repeatedly, investigate the token/UUID generator."],"tags":["auth","session","concurrency","transient"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}