Project: bamboo
Issue BAM-9231: Race condition can create duplicate plan keys, causing Bamboo to fail to start
Looks like a double-post of a create plan form resulted in duplicate plan key creation: {noformat} bamboo=# select build_id, buildkey from build; build_id | buildkey ----------+---------- 393217 | TRUNK 1507329 | JSTMVN 1507330 | JSTMVN 393218 | JOB1 {noformat} Excerpt from the Bamboo logs at that time: {noformat} @400000004e166cf406b6c1f4 2011-07-07 21:35:22,112 INFO [TP-Processor15] [AccessLogFilter] sysadmin POST https://sdog.jira.com/builds/build/admin/create/createPlan.action 103093kb @400000004e166d0d0c95cb4c 2011-07-07 21:35:47,211 INFO [TP-Processor17] [AccessLogFilter] sysadmin POST https://sdog.jira.com/builds/build/admin/create/createPlan.action 114482kb @400000004e166d1429151cdc 2011-07-07 21:35:54,685 INFO [TP-Processor15] [PlanCreationTemplate] Creating plan with key: JSTDEV-JSTMVN @400000004e166d14301380b4 2011-07-07 21:35:54,803 INFO [TP-Processor15] [PlanCreationTemplate] New build created with key JSTDEV-JSTMVN @400000004e166d1432779bec 2011-07-07 21:35:54,844 INFO [TP-Processor17] [PlanCreationTemplate] Creating plan with key: JSTDEV-JSTMVN @400000004e166d1434823ce4 2011-07-07 21:35:54,852 ERROR [AtlassianEvent::0-BAM::EVENTS:pool-1-thread-6] [ChainExecutionManagerImpl] Could not start executing Plan 'JSTDEV-JSTMVN' as the plan did not have any stages defined @400000004e166d14348244b4 2011-07-07 21:35:54,878 ERROR [TP-Processor17] [FiveOhOh] 500 Exception was thrown. @400000004e166d143482489c org.springframework.dao.IncorrectResultSizeDataAccessException: query did not return a unique result: 2 @400000004e166d143482489c at org.springframework.orm.hibernate.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:590) @400000004e166d143482600c at org.springframework.orm.hibernate.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:353) @400000004e166d14348263f4 at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:375) @400000004e166d14348267dc at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:337) @400000004e166d1434826bc4 at com.atlassian.bamboo.plan.PlanHibernateDao.getPlanByKey(PlanHibernateDao.java:43) @400000004e166d1434826fac at sun.reflect.GeneratedMethodAccessor225.invoke(Unknown Source) @400000004e166d1434826fac at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) @400000004e166d143482871c at java.lang.reflect.Method.invoke(Method.java:597) @400000004e166d1434828b04 at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:304) @400000004e166d1434828b04 at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182) @400000004e166d1434828eec at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149) @400000004e166d14348296bc at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106) @400000004e166d14348296bc at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) @400000004e166d1434829aa4 at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) @400000004e166d1434829e8c at $Proxy7.getPlanByKey(Unknown Source) @400000004e166d1434829e8c at com.atlassian.bamboo.plan.PlanManagerImpl.getPlanByKey(PlanManagerImpl.java:91) @400000004e166d143482a274 at com.atlassian.bamboo.plan.PlanManagerImpl.getPlanByKey(PlanManagerImpl.java:85) {noformat} This completely breaks Bamboo. It can no longer even start up without throwing the {{IncorrectResultSizeDataAccessException}}. Ideally, the uniqueness of this key should be enforced via a database constraint.
Story points: 2