TechnitiumSoftware/DnsServer · error · DnsWebServiceException

Error while creating session. Please try again.

Error message

Error while creating session. Please try again.

What it means

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'.

Source

Thrown at DnsServerCore/Auth/AuthManager.cs:1166

            {
                if (session.Value.User.Equals(user) && !session.Value.HasExpired())
                    userSessions.Add(session.Value);
            }

            return userSessions;
        }

        public async Task<UserSession> CreateSessionAsync(UserSessionType type, string tokenName, string username, string password, string totp, IPAddress remoteAddress, string userAgent)
        {
            User user = await AuthenticateUserAsync(username, password, totp, remoteAddress);

            if (type == UserSessionType.ClusterApiToken)
                throw new InvalidOperationException();

            UserSession session = new UserSession(type, tokenName, user, remoteAddress, userAgent);

            if (!_sessions.TryAdd(session.Token, session))
                throw new DnsWebServiceException("Error while creating session. Please try again.");

            user.LoggedInFrom(remoteAddress);

            return session;
        }

        public UserSession CreateSession(UserSessionType type, string tokenName, string username, IPAddress remoteAddress, string userAgent)
        {
            User user = GetUser(username);
            if (user is null)
                throw new DnsWebServiceException("No such user exists: " + username);

            return CreateSession(type, tokenName, user, remoteAddress, userAgent);
        }

        public UserSession CreateSession(UserSessionType type, string tokenName, User user, IPAddress remoteAddress, string userAgent)
        {
            if (user.Disabled)

View on GitHub (pinned to d0484b6c1e)

Solutions

  1. Retry the login/token creation once; a new token will be generated.
  2. If it recurs, investigate the session token generator / UUID uniqueness.
  3. As a last resort, restarting the service clears in-memory sessions.
Defensive patterns

Strategy: retry

Validate before calling

// No meaningful pre-check: token collisions are random and not predictable.

Try / catch

async Task<SessionInfo> LoginWithRetry(string user, string pass, string totp)
{
    try { return await client.LoginAsync(user, pass, totp); }
    catch (HttpApiClientException ex) when (ex.Message.Contains("Error while creating session"))
    { return await client.LoginAsync(user, pass, totp); }
}

Prevention

When it happens

Trigger: 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).

Common situations: Effectively never in practice unless the RNG/UUID source is broken or seeded identically across nodes; a retry resolves it.

Related errors


AI-assisted analysis of TechnitiumSoftware/DnsServer@d0484b6c1e (2026-08-13). Data as JSON: /api/errors/13ff200b0a6b38f7. Report an issue: GitHub.