Bamboo fails to synchronize with an external user management system due to a duplicate entry

Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.

Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. 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:

atlassian-bamboo.log

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 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:

atlassian-bamboo.log

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 2021-03-08 16:49:45,932 WARN [atlassian-scheduler-quartz2.local_Worker-4] [SqlExceptionHelper] SQL Error: 1062, SQLState: 23000 2021-03-08 16:49:45,932 ERROR [atlassian-scheduler-quartz2.local_Worker-4] [SqlExceptionHelper] Duplicate entry 'USERNAME' for key 'USER_NAME' 2021-03-08 16:49:45,933 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) at com.atlassian.bamboo.core.ScopedExclusionServiceImpl.withLock(ScopedExclusionServiceImpl.java:63) at com.atlassian.bamboo.user.rename.UserRenameServiceImpl.renameUser(UserRenameServiceImpl.java:102) at com.atlassian.bamboo.user.rename.UserRenameServiceImpl.onUserRenamedEvent(UserRenameServiceImpl.java:162) at sun.reflect.GeneratedMethodAccessor4074.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.atlassian.event.internal.SingleParameterMethodListenerInvoker.invoke(SingleParameterMethodListenerInvoker.java:42) at com.atlassian.event.internal.AsynchronousAbleEventDispatcher.lambda$null$0(AsynchronousAbleEventDispatcher.java:37) at com.atlassian.event.internal.AsynchronousAbleEventDispatcher.dispatch(AsynchronousAbleEventDispatcher.java:85) at com.atlassian.bamboo.event.spi.BambooEventDispatcher.dispatch(BambooEventDispatcher.java:34) at com.atlassian.event.internal.LockFreeEventPublisher$Publisher.dispatch(LockFreeEventPublisher.java:215) at com.atlassian.event.internal.LockFreeEventPublisher.publish(LockFreeEventPublisher.java:88) at com.atlassian.bamboo.event.TxAwareEventPublisher.publish(TxAwareEventPublisher.java:20) at java.util.ArrayList.forEach(Unknown Source) at com.atlassian.crowd.core.event.DelegatingMultiEventPublisher.publishAll(DelegatingMultiEventPublisher.java:19) at com.atlassian.crowd.directory.DbCachingRemoteChangeOperations.publishEvents(DbCachingRemoteChangeOperations.java:894) at com.atlassian.crowd.directory.DbCachingRemoteChangeOperations.publishEvent(DbCachingRemoteChangeOperations.java:888) at com.atlassian.crowd.directory.DbCachingRemoteChangeOperations.updateUsers(DbCachingRemoteChangeOperations.java:280) at sun.reflect.GeneratedMethodAccessor3940.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:295) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) at com.sun.proxy.$Proxy1834.updateUsers(Unknown Source) at com.atlassian.crowd.directory.DirectoryCacheImplUsingChangeOperations.addOrUpdateCachedUsers(DirectoryCacheImplUsingChangeOperations.java:58) at com.atlassian.crowd.directory.ldap.cache.RemoteDirectoryCacheRefresher.synchroniseAllUsers(RemoteDirectoryCacheRefresher.java:94) at com.atlassian.crowd.directory.synchronisation.cache.AbstractCacheRefresher.synchroniseAll(AbstractCacheRefresher.java:45) at com.atlassian.crowd.directory.ldap.cache.EventTokenChangedCacheRefresher.synchroniseAll(EventTokenChangedCacheRefresher.java:62) at com.atlassian.crowd.directory.DbCachingRemoteDirectory.synchroniseCache(DbCachingRemoteDirectory.java:1052) at com.atlassian.crowd.manager.directory.DirectorySynchroniserImpl.lambda$synchronise$0(DirectorySynchroniserImpl.java:80) at com.atlassian.crowd.audit.NoOpAuditLogContext.withAuditLogSource(NoOpAuditLogContext.java:17) at com.atlassian.crowd.manager.directory.DirectorySynchroniserImpl.synchronise(DirectorySynchroniserImpl.java:78) at sun.reflect.GeneratedMethodAccessor2739.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:295) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) at com.sun.proxy.$Proxy169.synchronise(Unknown Source) at com.atlassian.crowd.directory.DbCachingDirectoryPoller.pollChanges(DbCachingDirectoryPoller.java:45) at com.atlassian.crowd.manager.directory.monitor.poller.DirectoryPollerJobRunner.runJob(DirectoryPollerJobRunner.java:92) at com.atlassian.scheduler.core.JobLauncher.runJob(JobLauncher.java:134) at com.atlassian.scheduler.core.JobLauncher.launchAndBuildResponse(JobLauncher.java:106) at com.atlassian.scheduler.core.JobLauncher.launch(JobLauncher.java:90) at com.atlassian.scheduler.quartz2.Quartz2Job.execute(Quartz2Job.java:28) at org.quartz.core.JobRunShell.run(JobRunShell.java:202) at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573) Caused by: org.hibernate.exception.ConstraintViolationException: error executing work at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:59) at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99) at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.coordinateWork(JdbcCoordinatorImpl.java:325) at org.hibernate.internal.SessionImpl.doWork(SessionImpl.java:2408) at org.hibernate.internal.SessionImpl.doWork(SessionImpl.java:2393) at sun.reflect.GeneratedMethodAccessor3970.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.springframework.orm.hibernate5.HibernateTemplate$CloseSuppressingInvocationHandler.invoke(HibernateTemplate.java:1227) at com.sun.proxy.$Proxy323.doWork(Unknown Source) at com.atlassian.bamboo.user.rename.UserRenameServiceImpl$1.lambda$doInTransactionWithoutResult$1(UserRenameServiceImpl.java:119) at org.springframework.orm.hibernate5.HibernateTemplate.doExecute(HibernateTemplate.java:384) ... 61 more Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry 'USERNAME' for key 'USER_NAME' at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at com.mysql.jdbc.Util.handleNewInstance(Util.java:425) at com.mysql.jdbc.Util.getInstance(Util.java:408) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3976) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3912) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2530) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2683) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2486) at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1858) at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2079) at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2013) at com.mysql.jdbc.PreparedStatement.executeLargeUpdate(PreparedStatement.java:5104) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1998) at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUpdate(NewProxyPreparedStatement.java:462) at com.atlassian.bamboo.user.rename.UserRenameHelper.updateUserInTable(UserRenameHelper.java:38) at com.atlassian.bamboo.user.rename.UserRenameHelper.updateUserInTable(UserRenameHelper.java:23) at com.atlassian.bamboo.user.rename.UserRenameHelper.renameUserInAuthAttemptInfo(UserRenameHelper.java:60) at com.atlassian.bamboo.user.rename.UserRenameServiceImpl.doRenameUser(UserRenameServiceImpl.java:174) at com.atlassian.bamboo.user.rename.UserRenameServiceImpl.access$200(UserRenameServiceImpl.java:37) at com.atlassian.bamboo.user.rename.UserRenameServiceImpl$1.lambda$null$0(UserRenameServiceImpl.java:127) at org.hibernate.jdbc.WorkExecutor.executeWork(WorkExecutor.java:37) at org.hibernate.internal.SessionImpl$1.accept(SessionImpl.java:2389) at org.hibernate.internal.SessionImpl$1.accept(SessionImpl.java:2386) at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.coordinateWork(JdbcCoordinatorImpl.java:320) ... 70 more

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 might be misleading, since this error will occur even when a full synchronization happens.

1 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.
  • The user with user name "USERNAME" might not exist prior the synchronization, meaning the error can be misleading when troubleshooting the problem.

1 2021-03-08 16:49:45,932 ERROR [atlassian-scheduler-quartz2.local_Worker-4] [SqlExceptionHelper] Duplicate entry 'USERNAME' for key 'USER_NAME'

The key to solve this problem can be seen in the full stacktrace, in line 105

1 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: renaming 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:

  1. Stop Bamboo.

  2. Run the query

  3. 1 delete from AUTH_ATTEMPT_INFO where user_name = 'USERNAME';
  4. Start Bamboo again.

  5. Try to sync your directory manually again.

Updated on March 13, 2025

Still need help?

The Atlassian Community is here for you.