Uploaded image for project: 'Crowd Data Center'
  1. Crowd Data Center
  2. CWD-998

Simultaneous authentication attempts by same user throws ConstraintViolationException

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: Medium Medium
    • None
    • 1.3.2
    • Database
    • None

      If there are two simultaneous authentication attempts by the same user (e.g. two attempts to create the same token), this can cause a ConstraintViolationException to be thrown. The second attempt to authenticate will fail with this exception.

      Work around

      Change Session Store configuration in memory: http://confluence.atlassian.com/display/CROWD/Session+Configuration

            [CWD-998] Simultaneous authentication attempts by same user throws ConstraintViolationException

            Ben Longhurst (Inactive) made changes -
            Remote Link New: This issue links to "Page (Confluence)" [ 556205 ]
            Mareusz (Inactive) made changes -
            Resolution New: Won't Fix [ 2 ]
            Status Original: Long Term Backlog [ 12073 ] New: Closed [ 6 ]

            The problem described in the issue is not a bug, but expected behavior. The database prevents two parallel threads to insert the same token for a single user, which prevents some other problems from happening.

            The only problem is that errors are being logged, which could cause some kind of anxiety for someone reading the logs, because it might make them think that there is something going seriously wrong. Unfortunately Crowd's architecture doesn't allow to mitigate the problem (just not print the log) for this specific error, as we are talking about different kind of messages and error codes for every JDBC driver and database supported.

            Mareusz (Inactive) added a comment - The problem described in the issue is not a bug, but expected behavior. The database prevents two parallel threads to insert the same token for a single user, which prevents some other problems from happening. The only problem is that errors are being logged, which could cause some kind of anxiety for someone reading the logs, because it might make them think that there is something going seriously wrong. Unfortunately Crowd's architecture doesn't allow to mitigate the problem (just not print the log) for this specific error, as we are talking about different kind of messages and error codes for every JDBC driver and database supported.

            Mareusz (Inactive) added a comment - - edited

            Another example of the issue:

            2019-08-28 16:14:20,890 http-nio-8095-exec-927 ERROR [jdbc.batch.internal.BatchingBatch] HHH000315: Exception executing batch [java.sql.BatchUpdateException: Batch entry 0 insert into cwd_token (directory_id, entity_name, random_number, identifier_hash, random_hash, created_date, last_accessed_date, last_accessed_time, duration, id) values (-1, 'jira', 703609563597971212, 'hVtW5FElx8qNjHjM_6Kw8A', 'isOjJSE3l9_-lMf5U_zlNP__________amlyYQ', '2019-08-28 16:14:20.811+02', '2019-08-28 16:14:20.811+02', 1567001660811, 60, 589845) was aborted: ERROR: duplicate key value violates unique constraint "uk_token_id_hash"
              Detail: Key (identifier_hash)=(hVtW5FElx8qNjHjM_6Kw8A) already exists.
              Location: File: nbtinsert.c, Routine: _bt_check_unique, Line: 433
              Server SQLState: 23505  Call getNextException to see other errors in the batch.], SQL: insert into cwd_token (directory_id, entity_name, random_number, identifier_hash, random_hash, created_date, last_accessed_date, last_accessed_time, duration, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
            2019-08-28 16:14:20,893 http-nio-8095-exec-927 WARN [engine.jdbc.spi.SqlExceptionHelper] SQL Error: 0, SQLState: 23505
            2019-08-28 16:14:20,896 http-nio-8095-exec-927 ERROR [engine.jdbc.spi.SqlExceptionHelper] Batch entry 0 insert into cwd_token (directory_id, entity_name, random_number, identifier_hash, random_hash, created_date, last_accessed_date, last_accessed_time, duration, id) values (-1, 'jira', 703609563597971212, 'hVtW5FElx8qNjHjM_6Kw8A', 'isOjJSE3l9_-lMf5U_zlNP__________amlyYQ', '2019-08-28 16:14:20.811+02', '2019-08-28 16:14:20.811+02', 1567001660811, 60, 589845) was aborted: ERROR: duplicate key value violates unique constraint "uk_token_id_hash"
              Detail: Key (identifier_hash)=(hVtW5FElx8qNjHjM_6Kw8A) already exists.
              Location: File: nbtinsert.c, Routine: _bt_check_unique, Line: 433
              Server SQLState: 23505  Call getNextException to see other errors in the batch.
            2019-08-28 16:14:20,896 http-nio-8095-exec-927 WARN [engine.jdbc.spi.SqlExceptionHelper] SQL Error: 0, SQLState: 23505
            2019-08-28 16:14:20,896 http-nio-8095-exec-927 ERROR [engine.jdbc.spi.SqlExceptionHelper] ERROR: duplicate key value violates unique constraint "uk_token_id_hash"
              Detail: Key (identifier_hash)=(hVtW5FElx8qNjHjM_6Kw8A) already exists.
              Location: File: nbtinsert.c, Routine: _bt_check_unique, Line: 433
              Server SQLState: 23505
            

            Spotted on Postgres 9.6.

            The message could depend on the actual database being used and the JDBC driver.

            Mareusz (Inactive) added a comment - - edited Another example of the issue: 2019-08-28 16:14:20,890 http-nio-8095-exec-927 ERROR [jdbc.batch.internal.BatchingBatch] HHH000315: Exception executing batch [java.sql.BatchUpdateException: Batch entry 0 insert into cwd_token (directory_id, entity_name, random_number, identifier_hash, random_hash, created_date, last_accessed_date, last_accessed_time, duration, id) values (-1, 'jira' , 703609563597971212, 'hVtW5FElx8qNjHjM_6Kw8A' , 'isOjJSE3l9_-lMf5U_zlNP__________amlyYQ' , '2019-08-28 16:14:20.811+02' , '2019-08-28 16:14:20.811+02' , 1567001660811, 60, 589845) was aborted: ERROR: duplicate key value violates unique constraint "uk_token_id_hash" Detail: Key (identifier_hash)=(hVtW5FElx8qNjHjM_6Kw8A) already exists. Location: File: nbtinsert.c, Routine: _bt_check_unique, Line: 433 Server SQLState: 23505 Call getNextException to see other errors in the batch.], SQL: insert into cwd_token (directory_id, entity_name, random_number, identifier_hash, random_hash, created_date, last_accessed_date, last_accessed_time, duration, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) 2019-08-28 16:14:20,893 http-nio-8095-exec-927 WARN [engine.jdbc.spi.SqlExceptionHelper] SQL Error: 0, SQLState: 23505 2019-08-28 16:14:20,896 http-nio-8095-exec-927 ERROR [engine.jdbc.spi.SqlExceptionHelper] Batch entry 0 insert into cwd_token (directory_id, entity_name, random_number, identifier_hash, random_hash, created_date, last_accessed_date, last_accessed_time, duration, id) values (-1, 'jira' , 703609563597971212, 'hVtW5FElx8qNjHjM_6Kw8A' , 'isOjJSE3l9_-lMf5U_zlNP__________amlyYQ' , '2019-08-28 16:14:20.811+02' , '2019-08-28 16:14:20.811+02' , 1567001660811, 60, 589845) was aborted: ERROR: duplicate key value violates unique constraint "uk_token_id_hash" Detail: Key (identifier_hash)=(hVtW5FElx8qNjHjM_6Kw8A) already exists. Location: File: nbtinsert.c, Routine: _bt_check_unique, Line: 433 Server SQLState: 23505 Call getNextException to see other errors in the batch. 2019-08-28 16:14:20,896 http-nio-8095-exec-927 WARN [engine.jdbc.spi.SqlExceptionHelper] SQL Error: 0, SQLState: 23505 2019-08-28 16:14:20,896 http-nio-8095-exec-927 ERROR [engine.jdbc.spi.SqlExceptionHelper] ERROR: duplicate key value violates unique constraint "uk_token_id_hash" Detail: Key (identifier_hash)=(hVtW5FElx8qNjHjM_6Kw8A) already exists. Location: File: nbtinsert.c, Routine: _bt_check_unique, Line: 433 Server SQLState: 23505 Spotted on Postgres 9.6. The message could depend on the actual database being used and the JDBC driver.
            Monique Khairuliana (Inactive) made changes -
            Epic Link Original: CWD-4701 [ 598559 ]
            Monique Khairuliana (Inactive) made changes -
            Workflow Original: Simplified Crowd Development Workflow v2 - restricted [ 1509877 ] New: JAC Bug Workflow v3 [ 3366038 ]
            Status Original: Verified [ 10005 ] New: Long Term Backlog [ 12073 ]
            SET Analytics Bot made changes -
            UIS New: 2
            Mareusz (Inactive) made changes -
            Status Original: Open [ 1 ] New: Verified [ 10005 ]
            Mareusz (Inactive) made changes -
            Epic Link New: CWD-4701 [ 598559 ]
            Bugfix Automation Bot made changes -
            Support reference count Original: 3 New: 2

              Unassigned Unassigned
              donna@atlassian.com DonnaA
              Affected customers:
              3 This affects my team
              Watchers:
              8 Start watching this issue

                Created:
                Updated:
                Resolved: