Sonarqube 7.9.5 LTS failing to start due to duplicate key error

Template for a good bug report, formatted with Markdown:

  • versions used (SonarQube, Scanner, Plugin, and any relevant extension)
    SonarQube 7.9.5
    PostgreSQL 10.15

Fresh install, clean database.

  • error observed (wrap logs/code around triple quote ``` for proper formatting)
    web.log
2021.02.20 21:56:02 ERROR web[][o.s.s.p.Platform] Background initialization failed. Stopping SonarQube
org.apache.ibatis.exceptions.PersistenceException: 
### Error updating database.  Cause: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "rule_id_deprecated_rule_keys"
  Detail: Key (rule_id)=(2476) already exists.
### The error may exist in org.sonar.db.rule.RuleMapper
### The error may involve org.sonar.db.rule.RuleMapper.insertDeprecatedRuleKey-Inline
### The error occurred while setting parameters
### Cause: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "rule_id_deprecated_rule_keys"
  Detail: Key (rule_id)=(2476) already exists.
	at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:199)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:184)
	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:62)
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:58)
	at com.sun.proxy.$Proxy51.insertDeprecatedRuleKey(Unknown Source)
	at org.sonar.db.rule.RuleDao.insert(RuleDao.java:265)
	at org.sonar.server.rule.RegisterRules.lambda$updateDeprecatedKeys$3(RegisterRules.java:614)
	at java.base/java.lang.Iterable.forEach(Iterable.java:75)
	at org.sonar.server.rule.RegisterRules.updateDeprecatedKeys(RegisterRules.java:614)
	at org.sonar.server.rule.RegisterRules.registerRule(RegisterRules.java:379)
	at org.sonar.server.rule.RegisterRules.start(RegisterRules.java:131)
	at org.sonar.core.platform.StartableCloseableSafeLifecyleStrategy.start(StartableCloseableSafeLifecyleStrategy.java:40)
	at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.start(AbstractInjectionFactory.java:84)
	at org.picocontainer.behaviors.AbstractBehavior.start(AbstractBehavior.java:169)
	at org.picocontainer.behaviors.Stored$RealComponentLifecycle.start(Stored.java:132)
	at org.picocontainer.behaviors.Stored.start(Stored.java:110)
	at org.picocontainer.DefaultPicoContainer.potentiallyStartAdapter(DefaultPicoContainer.java:1016)
	at org.picocontainer.DefaultPicoContainer.startAdapters(DefaultPicoContainer.java:1009)
	at org.picocontainer.DefaultPicoContainer.start(DefaultPicoContainer.java:767)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:135)
	at org.sonar.server.platform.platformlevel.PlatformLevel.start(PlatformLevel.java:90)
	at org.sonar.server.platform.platformlevel.PlatformLevelStartup.access$001(PlatformLevelStartup.java:48)
	at org.sonar.server.platform.platformlevel.PlatformLevelStartup$1.doPrivileged(PlatformLevelStartup.java:85)
	at org.sonar.server.user.DoPrivileged.execute(DoPrivileged.java:46)
	at org.sonar.server.platform.platformlevel.PlatformLevelStartup.start(PlatformLevelStartup.java:82)
	at org.sonar.server.platform.Platform.executeStartupTasks(Platform.java:196)
	at org.sonar.server.platform.Platform.access$400(Platform.java:46)
	at org.sonar.server.platform.Platform$1.lambda$doRun$1(Platform.java:121)
	at org.sonar.server.platform.Platform$AutoStarterRunnable.runIfNotAborted(Platform.java:371)
	at org.sonar.server.platform.Platform$1.doRun(Platform.java:121)
	at org.sonar.server.platform.Platform$AutoStarterRunnable.run(Platform.java:355)
	at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "rule_id_deprecated_rule_keys"
  Detail: Key (rule_id)=(2476) 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:47)
	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:197)
	... 31 common frames omitted
2021.02.20 21:56:02 INFO  web[][o.s.p.ProcessEntryPoint] Hard stopping process
2021.02.20 21:56:02 INFO  web[][o.s.s.n.NotificationDaemon] Notification service stopped
  • steps to reproduce

Start SonarQube

  • potential workaround

NA

Hi @harbottle ,

Welcome to SonarSource community! :sonarsource:

Can you go to your sonar.properties file and set the sonar.log.level=TRACE then reattempt startup of SonarQube? Please attach the entire web.log file on your next response.

Joe

@Joe

web.log attached from fresh install in identical environmentweb.zip (482.1 KB)

Thanks!

@Joe I’ve fixed this. It was an incompatibility with the latest version of the javascript plugin. I’ve reverted the plugin and all is good.

1 Like

@harbottle thanks for confirming the issue and notifying me! I see what you mean now:

2021.02.21 16:27:31 TRACE web[][sql] time=0ms | sql=INSERT INTO deprecated_rule_keys ( uuid, rule_id, old_repository_key, old_rule_key, created_at ) values ( ?, ?, ?, ?, ? ) | params=AXfFat6uatqsu1_a-oA9, 2476, javascript, UnreachableCode, 1613924851374
2021.02.21 16:27:31 TRACE web[][sql] time=2ms | sql=INSERT INTO deprecated_rule_keys ( uuid, rule_id, old_repository_key, old_rule_key, created_at ) values ( ?, ?, ?, ?, ? ) | params=AXfFat6uatqsu1_a-oA-, 2476, javascript, S1736, 1613924851374

That duplicate key is odd and I’m glad you found the source of your problem. Have a good day!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.