Cannot delete SonarCloud project, PostgreSQL error

Hi,

I cannot delete my SonarCloud project, it has gotten into a weird state. Here is the URL
https://sonarcloud.io/project/background_tasks?id=artnetworldwide-utility-authentication-frontend

and the URL of the problematic pull request
https://sonarcloud.io/dashboard?id=artnetworldwide-utility-authentication-frontend&pullRequest=92

And the error in the background tasks

    org.apache.ibatis.exceptions.PersistenceException: 
    ### Error updating database.  Cause: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "project_branches_kee_key_type"
      Detail: Key (project_uuid, kee, key_type)=(AWnkeQn68FPh9JKrfdOa, 92, PULL_REQUEST) already exists.
    ### The error may involve org.sonar.db.component.BranchMapper.insert-Inline
    ### The error occurred while setting parameters
    ### SQL: insert into project_branches (       uuid,       project_uuid,       kee,       key_type,       branch_type,       merge_branch_uuid,       pull_request_binary,       manual_baseline_analysis_uuid,       created_at,       updated_at     ) values (       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?     )
    ### Cause: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "project_branches_kee_key_type"
      Detail: Key (project_uuid, kee, key_type)=(AWnkeQn68FPh9JKrfdOa, 92, PULL_REQUEST) already exists.
    	at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
    	at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:200)
    	at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:185)
    	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:58)
    	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
    	at com.sun.proxy.$Proxy54.insert(Unknown Source)
    	at org.sonar.db.component.BranchDao.upsert(BranchDao.java:50)
    	at org.sonar.ce.task.projectanalysis.component.BranchPersisterImpl.persist(BranchPersisterImpl.java:54)
    	at org.sonar.ce.task.projectanalysis.step.PersistComponentsStep.execute(PersistComponentsStep.java:96)
    	at org.sonar.ce.task.step.ComputationStepExecutor.executeStep(ComputationStepExecutor.java:81)
    	at org.sonar.ce.task.step.ComputationStepExecutor.executeSteps(ComputationStepExecutor.java:72)
    	at org.sonar.ce.task.step.ComputationStepExecutor.execute(ComputationStepExecutor.java:59)
    	at org.sonar.ce.task.projectanalysis.taskprocessor.ReportTaskProcessor.process(ReportTaskProcessor.java:81)
    	at org.sonar.ce.taskprocessor.CeWorkerImpl$ExecuteTask.executeTask(CeWorkerImpl.java:207)
    	at org.sonar.ce.taskprocessor.CeWorkerImpl$ExecuteTask.run(CeWorkerImpl.java:189)
    	at org.sonar.ce.taskprocessor.CeWorkerImpl.findAndProcessTask(CeWorkerImpl.java:156)
    	at org.sonar.ce.taskprocessor.CeWorkerImpl$TrackRunningState.get(CeWorkerImpl.java:131)
    	at org.sonar.ce.taskprocessor.CeWorkerImpl.call(CeWorkerImpl.java:83)
    	at org.sonar.ce.taskprocessor.CeWorkerImpl.call(CeWorkerImpl.java:51)
    	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
    	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    	at java.lang.Thread.run(Thread.java:748)
    Caused by: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "project_branches_kee_key_type"
      Detail: Key (project_uuid, kee, key_type)=(AWnkeQn68FPh9JKrfdOa, 92, PULL_REQUEST) already exists.
    	at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2440)
    	at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2183)
    	at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:308)
    	at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:441)
    	at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:365)
    	at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:143)
    	at org.postgresql.jdbc.PgPreparedStatement.execute(PgPreparedStatement.java:132)
    	at org.apache.commons.dbcp2.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:94)
    	at org.apache.commons.dbcp2.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:94)
    	at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:46)
    	at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:74)
    	at org.apache.ibatis.executor.ReuseExecutor.doUpdate(ReuseExecutor.java:52)
    	at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)
    	at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76)
    	at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:198)
    	... 25 more

Hi Paul,

our team is going to look at this.

Would you be able to remind the steps which led to this state? This could help us understand how to fix this issue to prevent this situation in the future.

Thanks!

OK so I don’t have exact steps to reproduce but I do have some avenues that could be explored.

We have 2 Sonar projects linked to this one repository, keep in mind that Sonar pull request analysis are created on both repositories. This is not what we normally do but this repository has two separate code projects inside. One NodeJS and one .NET core. There are two entirely different scans happening for every commit on this repository. This has not been a problem for months, but we have not had this issue on other repositories where we have a 1 to 1 github repository to sonar project relationship.

The two projects linked to one repository
https://sonarcloud.io/dashboard?id=artnetworldwide-utility-authentication-backend
https://sonarcloud.io/dashboard?id=artnetworldwide-utility-authentication-frontend

Another possibility is that multiple concurrent scans were taking place on different branches/same repository, because we use a tool called Renovate in the night to create new branches with package updates. Every time a branch is created we scan it with Sonar. This might have caused this problem?

Hi Paul,

Thanks for the details. Your project has been fixed and the root problem is being fixed. Please let us know if the error occurs again.

Sorry for the inconvenience.