Duplicate key error getting after upgrading sonar 9.9.1 with Postgres 14

Make sure to tell us:

  • Sonar upgraded to 9.9.1 with Postgres 14. Getting duplicate key error if I click quality gate tile in sonar UI. Quality gate page is blank.

    Jenkins pipeline failing.
    Logs:
org.sonarqube.ws.client.HttpException: Error 400 on http://sonarqube:9000/sonar/api/qualitygates/project_status?analysisId=AYlIin_1KdykgZn9PS36 : {"errors":[{"msg":"Duplicate key AYlFgfScO7nd2VyqMYbQ"}]}
	at hudson.plugins.sonar.client.HttpClient.getHttp(HttpClient.java:48)
	at hudson.plugins.sonar.client.WsClient.requestQualityGateStatus(WsClient.java:70)
	at org.sonarsource.scanner.jenkins.pipeline.WaitForQualityGateStep$Execution.lambda$checkTaskCompleted$0(WaitForQualityGateStep.java:241)
	at org.sonarsource.scanner.jenkins.pipeline.WaitForQualityGateStep$Execution.checkQualityGate(WaitForQualityGateStep.java:294)
	at org.sonarsource.scanner.jenkins.pipeline.WaitForQualityGateStep$Execution.checkTaskCompleted(WaitForQualityGateStep.java:241)
	at org.sonarsource.scanner.jenkins.pipeline.WaitForQualityGateStep$Execution.start(WaitForQualityGateStep.java:176)
	at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:322)
	at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:196)
	at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:124)
	at jdk.internal.reflect.GeneratedMethodAccessor346.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:98)
	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1225)
	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1034)
	at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:41)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
	at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:180)
	at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:23)
	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:163)
	at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:178)
	at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:182)
	at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:152)
	at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:152)
	at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:152)
	at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:152)
	at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:152)
	at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17)
	at WorkflowScript.run(WorkflowScript:202)
	at ___cps.transform___(Native Method)
	at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:90)
	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:116)
	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixName(FunctionCallBlock.java:80)
	at jdk.internal.reflect.GeneratedMethodAccessor340.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
	at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
	at com.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21)
	at com.cloudbees.groovy.cps.Next.step(Next.java:83)
	at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:152)
	at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:146)
	at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:136)
	at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:275)
	at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:146)
	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:18)
	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:51)
	at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:187)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:420)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:330)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:294)
	at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:67)
	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
	at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:139)
	at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
	at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:68)
	at jenkins.util.ErrorLoggingExecutorService.lambda$wrap$0(ErrorLoggingExecutorService.java:51)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.base/java.lang.Thread.run(Unknown Source)
Finished: FAILURE

Please check and guide me.

Hi,

This looks like a Jenkins stacktrace, rather than one from your SonarQube server logs.

Where are you clicking from? And what, if anything, shows up in your SonarQube server logs?

 
Ann

Hi Ann,

I found few logs and multiple token are there in sonar container logs. Got some violations logs.

Logs:

172.18.0.15 - - [13/Jul/2023:09:24:04 +0000] **"GET /sonar/api/measures/component?metricKeys=critical_violations,coverage,major_violations,blocker_violations&component=TodoGolang20 HTTP/1.1" 200 - "-" "curl/7.74.0" "AYlOhjsD034xoZaEAACe"**
172.18.0.13 - - [13/Jul/2023:09:24:06 +0000] "GET /sonar/api/ce/task?id=AYlOkBmriDJbCVyCARNx HTTP/1.1" 200 - "-" "Scanner for Jenkins" "AYlOhjsD034xoZaEAACf"
172.18.0.13 - - [13/Jul/2023:09:24:06 +0000] "GET /sonar/api/qualitygates/project_status?analysisId=AYlOkB3Zwk4YrdJnwfg3 HTTP/1.1" 400 - "-" "Scanner for Jenkins" "AYlOhjsD034xoZaEAACg"
172.18.0.13 - - [13/Jul/2023:09:24:06 +0000] "GET /sonar/api/ce/task?id=AYlOjCUHiDJbCVyCARNa HTTP/1.1" 200 - "-" "Scanner for Jenkins" "AYlOhjsD034xoZaEAACh"
172.18.0.13 - - [13/Jul/2023:09:24:06 +0000] "GET **/sonar/api/qualitygates/project_status?analysisId=AYlOjCa1wk4YrdJnwfYt HTTP/1.1" 400 - "-" "Scanner for Jenkins" "AYlOhjsD034xoZaEAACi"**

Getting 400 error in above while access the sonar qualitygate in above log.

In Sonar UI if I click on quality gate getting duplicate error.

In Jenkins pipeline job as well showing same token which is there in sonar UI qualitygate screenshot
org.sonarqube.ws.client.HttpException: Error 400 on http://sonarqube:9000/sonar/api/qualitygates/project_status?analysisId=AYlO1hGN4XFxLMQr-NQP : {“errors”:[{“msg”:“Duplicate key AYlOfz4_iDJbCVyCAHQs”}]}

Why duplicate key is coming? not sure.

Please check once and let me know.

Hi,

We try to keep it to one topic per thread. Otherwise it can get messy, fast. The errors the Jenkins scanner is getting is a different topic.

Regarding the ‘Duplicate key’ error, what do you see in your server logs?

 
Ann

Hi Ann,

Found below log.
172.18.0.13 - - [14/Jul/2023:05:08:06 +0000] “GET /sonar/api/qualitygates/list HTTP/1.0” 400 - “-” “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36” “AYlSv1RX/tK0RaRZAACg”

Kindly check.

Hi,

That’s from your access log, which is not one of the server logs discussed in the docs link I gave you.

 
Ann

Hi Ann,

I’m not able to find the logs on duplicate key in server logs which you shared.

But i’m getting duplicate key error, if I click quality gates in sonar UI.

why above error is coming?
Kindly guide me.

Hi,

When you looked at your server logs, did you see any errors in them?

 
Ann

Hi Ann,

I didn’t see any logs.

Hi,

SonarQube doesn’t run without generating logs. You need to find them.

 
Ann

Hi Ann,

I found logs on web.log
2023.07.18 16:25:56 INFO web[AYlpsmHUgury/TGNAAC9][o.s.u.c.UpdateCenter] The plugin ‘javascript’ version : 6.6.0.13923 has not been found on the update center.
2023.07.18 16:25:56 INFO web[AYlpsmHUgury/TGNAAC9][o.s.u.c.UpdateCenter] The plugin ‘kotlin’ version : 2.12.0.1956 has not been found on the update center.
2023.07.18 16:25:56 INFO web[AYlpsmHUgury/TGNAAC9][o.s.u.c.UpdateCenter] The plugin ‘php’ version : 3.27.1.9352 has not been found on the update center.
2023.07.18 16:25:56 INFO web[AYlpsmHUgury/TGNAAC9][o.s.u.c.UpdateCenter] The plugin ‘python’ version : 3.24.0.10784 has not been found on the update center.
2023.07.18 16:25:56 INFO web[AYlpsmHUgury/TGNAAC9][o.s.u.c.UpdateCenter] The plugin ‘ruby’ version : 1.11.0.3905 has not been found on the update center.
2023.07.18 16:25:56 INFO web[AYlpsmHUgury/TGNAAC9][o.s.u.c.UpdateCenter] The plugin ‘sonarscala’ version : 1.11.0.3905 has not been found on the update center.
2023.07.18 16:25:56 INFO web[AYlpsmHUgury/TGNAAC9][o.s.u.c.UpdateCenter] The plugin ‘text’ version : 2.0.2.1090 has not been found on the update center.
2023.07.18 16:25:56 INFO web[AYlpsmHUgury/TGNAAC9][o.s.u.c.UpdateCenter] The plugin ‘vbnet’ version : 8.51.0.59060 has not been found on the update center.
2023.07.18 16:25:56 INFO web[AYlpsmHUgury/TGNAAC9][o.s.u.c.UpdateCenter] The plugin ‘web’ version : 3.7.1.3306 has not been found on the update center.
2023.07.18 16:25:56 INFO web[AYlpsmHUgury/TGNAAC9][o.s.u.c.UpdateCenter] The plugin ‘xml’ version : 2.5.0.3376 has not been found on the update center.

But in this not able to find the duplicate key error logs.
Kindly check and guide.

Hi,

Is that the entirety of your web.log? No errors at all? Ever?

 
Ann

Hi Ann,
Find the full log of sonar_web.
sonarqube_web.log (122.2 KB)

Not able to find the duplicate key error.
Check once.

Hi,

Thanks for the log.

What do you see in your browser console when you get this error?

 
Ann

Hi Ann,

In the sonar UI if I click quality gates getting below error.

Kindly check.

Hi,

Can you open your browser’s Developer Tools and look at the Console, and see if there are any errors there when you get this error?

 
Ann

Hi Ann,

Getting below response in browser’s Developer Tool Console.

Check once.

Hi,

You’re getting a bad request error (400) for a very routine request. Is anonymous access allowed on your server? And if not, are you sure you’re logged in properly? I think a first step would be clearing your cookies and trying again (so that you would be reprompted to log in if needed). And then maybe

  • stop server
  • delete $SONARQUBE-HOME/data/es7
  • restart server

This doesn’t have the typical hallmarks of corrupt Elasticsearch indices, but it’s worth eliminating.

 
Ann

Hi Ann,

Anonymous access is not allowed and able to login with admin user with new password.
As suggested stopped sonar server and removed es7 folder and started the sonar server.
Cleared cookies and cache as well and login into sonar, still getting same issue.

Kindly check once.

Hi,

Thanks for jumping through the hoops. At the point, I’m out of ideas. I’ve flagged this for more expert eyes.

 
Ann