Bamboo fails to synchronize with an external user management system due to a duplicate entry
Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
When either an incremental or full synchronization is executed by Bamboo (automatically) or by a user (manually), the synchronizing will fail due to a duplicate entry.
Diagnosis
In the server logs, we will observe the following error:
2021-02-15 11:22:47,815 ERROR [atlassian-scheduler-quartz2.local_Worker-4] [EventTokenChangedCacheRefresher] Incremental synchronisation failed: com.atlassian.crowd.event.user.UserRenamedEvent is not supported by incremental sync.
(...)
2021-02-15 11:22:48,232 WARN [atlassian-scheduler-quartz2.local_Worker-4] [SqlExceptionHelper] SQL Error: 1062, SQLState: 23000
2021-02-15 11:22:48,232 ERROR [atlassian-scheduler-quartz2.local_Worker-4] [SqlExceptionHelper] Duplicate entry 'USERNAME' for key 'USER_NAME'
2021-02-15 11:22:48,233 ERROR [atlassian-scheduler-quartz2.local_Worker-4] [UserRenameServiceImpl] error while renaming user
org.springframework.dao.DataIntegrityViolationException: error executing work; SQL [n/a]; constraint [USER_NAME]; nested exception is org.hibernate.exception.ConstraintViolationException: error executing work
at org.springframework.orm.hibernate5.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:247)
at org.springframework.orm.hibernate5.HibernateTemplate.doExecute(HibernateTemplate.java:387)
at org.springframework.orm.hibernate5.HibernateTemplate.execute(HibernateTemplate.java:336)
at com.atlassian.bamboo.user.rename.UserRenameServiceImpl$1.doInTransactionWithoutResult(UserRenameServiceImpl.java:118)
at org.springframework.transaction.support.TransactionCallbackWithoutResult.doInTransaction(TransactionCallbackWithoutResult.java:36)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140)
at com.atlassian.bamboo.user.rename.UserRenameServiceImpl.lambda$renameUser$0(UserRenameServiceImpl.java:115)
(...)
Caused by: org.hibernate.exception.ConstraintViolationException: error executing work
at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:59)
(...)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry 'USERNAME' for key 'USER_NAME'
(...)
The full stacktrace is bigger and can be seen here:
Cause
In this case we can see that a user with user name "USERNAME" can't be synchronized because Bamboo is complaining of a duplicate entry.
There are a couple of things to mention about this messages:
- The message
2021-02-15 11:22:47,815 ERROR [atlassian-scheduler-quartz2.local_Worker-4] [EventTokenChangedCacheRefresher] Incremental synchronisation failed: com.atlassian.crowd.event.user.UserRenamedEvent is not supported by incremental sync.
might be misleading, since this error will occur even when a full synchronization happens.
- The user with user name "USERNAME" might not exist prior the synchronization, meaning the error
2021-03-08 16:49:45,932 ERROR [atlassian-scheduler-quartz2.local_Worker-4] [SqlExceptionHelper] Duplicate entry 'USERNAME' for key 'USER_NAME'
can be misleading when troubleshooting the problem.
The key to solve this problem can be seen in the full stacktrace, in line 105
at com.atlassian.bamboo.user.rename.UserRenameHelper.renameUserInAuthAttemptInfo(UserRenameHelper.java:60)
The reason why the operation fails is because there is data in the table AUTH_ATTEMPT_INFO colliding with this user name. The reason for this could vary: re-naming a user, creating a user that used to exist, a user existing in multiple user management systems that changed in some way, etc.
Solution
The way to fix this inconsistency is by manually deleting the entries from the table AUTH_ATTEMPT_INFO containing the problematic user name.
This solution will consist in deleting data directly from the Database. For preventive reasons, please make a backup of your Database before proceeding.
To proceed, please do the following:
- Stop Bamboo.
- Run the query
delete from AUTH_ATTEMPT_INFO where user_name = 'USERNAME';
- Start Bamboo again.
- Try to sync your directory manually again.