SQ 8.5 Docker image using Azure Postgressql

SonarQube version: 8.5 (docker)
Issue: Web Server startup failed
Errorstack:

java.lang.IllegalStateException: Fail to connect to database
        at org.sonar.db.DefaultDatabase.start(DefaultDatabase.java:86)
        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:136)
        at org.sonar.server.platform.platformlevel.PlatformLevel.start(PlatformLevel.java:90)
        at org.sonar.server.platform.platformlevel.PlatformLevel1.start(PlatformLevel1.java:166)
        at org.sonar.server.platform.PlatformImpl.start(PlatformImpl.java:213)
        at org.sonar.server.platform.PlatformImpl.startLevel1Container(PlatformImpl.java:172)
        at org.sonar.server.platform.PlatformImpl.init(PlatformImpl.java:86)
        at org.sonar.server.platform.web.PlatformServletContextListener.contextInitialized(PlatformServletContextListener.java:43)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4689)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5155)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1412)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1402)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.IllegalStateException: Can not connect to database. Please check connectivity and settings (see the properties prefixed by 'sonar.jdbc.').
        at org.sonar.db.DefaultDatabase.checkConnection(DefaultDatabase.java:118)
        at org.sonar.db.DefaultDatabase.start(DefaultDatabase.java:83)
        ... 24 common frames omitted
Caused by: java.sql.SQLException: Cannot create PoolableConnectionFactory (The connection attempt failed.)
        at org.apache.commons.dbcp2.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:669)
        at org.apache.commons.dbcp2.BasicDataSource.createDataSource(BasicDataSource.java:544)
        at org.apache.commons.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:753)
        at org.sonar.db.profiling.NullConnectionInterceptor.getConnection(NullConnectionInterceptor.java:31)
        at org.sonar.db.profiling.ProfiledDataSource.getConnection(ProfiledDataSource.java:317)
        at org.sonar.db.DefaultDatabase.checkConnection(DefaultDatabase.java:115)
        ... 25 common frames omitted
Caused by: org.postgresql.util.PSQLException: The connection attempt failed.
        at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:315)
        at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:51)
        at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:225)
        at org.postgresql.Driver.makeConnection(Driver.java:465)
        at org.postgresql.Driver.connect(Driver.java:264)
        at org.apache.commons.dbcp2.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:55)
        at org.apache.commons.dbcp2.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:355)
        at org.apache.commons.dbcp2.BasicDataSource.validateConnectionFactory(BasicDataSource.java:115)
        at org.apache.commons.dbcp2.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:665)
        ... 30 common frames omitted
Caused by: java.io.EOFException: null
        at org.postgresql.core.PGStream.receiveChar(PGStream.java:443)
        at org.postgresql.core.v3.ConnectionFactoryImpl.enableGSSEncrypted(ConnectionFactoryImpl.java:436)
        at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:144)
        at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:213)
        ... 38 common frames omitted

Herewith the docker-compose part for booting the SQ docker container:

  sonar:
    image: sonarqube:8.5-developer
    ports:
      - "9000:9000"
    volumes:
      - sonarqube_data:/opt/sonarqube/data
      - sonarqube_extensions:/opt/sonarqube/extensions
      - sonarqube_logs:/opt/sonarqube/logs
      - sonarqube_temp:/opt/sonarqube/temp
      - ./sonar.properties:/opt/sonarqube/conf/sonar.properties

the sonar.properties file contains:

sonar.jdbc.username=some_user
sonar.jdbc.password=some_pw
sonar.jdbc.url=jdbc:postgresql://xxxxx.postgres.database.azure.com:5432/xxxx

Hi @Jos_Wilbrink ,

welcome to the community :wave:

did you already check if something is blocking the connection between your sonarqube instance and the database you referenced?

Hi Tobias,

Thanks :slight_smile:
Well, it’s an upgrade. If I use image: sonarqube:8.4-developer in my docker-compose, everything works fine.

Thanks for helping out!

Hmm okay what is your network configuration look like? if you can reach the database server from the host system it might be an idea to use network_mode: "host" for the sq container to narrow down the problem

Changing to network_mode: host didn’t change anything in the errorstack.

In the same docker-compose environment I use Adminer to connect to the database, successful
When changing docker-compose to sonarqube:8.4-developer, the connection is successful, using the same sonar.properties file.

I started a local instance of postgres 11, within the same docker environment, changed the sonar properties to point to this new local instance and that seems to work.

so in the same docker compose stack or in another one, exposing it locally (docker run … -p 5432:5432) ?

I am trying to recreate this but for me this is working without a problem (note: with aws rds and not azure but at the end it is just the postgres jdbc driver), so i don’t think this is something with sonarqube directly, but more with the surrounding infrastructure

This is my compose file

version: "3"

services:
  sonarqube:
    image: sonarqube:8.5-community
    environment:
      SONAR_JDBC_URL: jdbc:postgresql://xxx.eu-west-1.rds.amazonaws.com:5432/postgres
      SONAR_JDBC_USERNAME: some_user
      SONAR_JDBC_PASSWORD: some_password
    volumes:
      - sonarqube_data:/opt/sonarqube/data
      - sonarqube_extensions:/opt/sonarqube/extensions
      - sonarqube_logs:/opt/sonarqube/logs
      - sonarqube_temp:/opt/sonarqube/temp
    ports:
      - "9000:9000"
volumes:
  sonarqube_data:
  sonarqube_extensions:
  sonarqube_logs:
  sonarqube_temp:

AWS RDS works for me as well.
So it’s a combination of 8.5 and azure postgres.

Hi @Jos_Wilbrink ,

we did some investigation and noticed that we upgraded the postgresql jdbc driver by 2 patch versions ( 42.2.14 to 42.2.16 ). and with that we dug deeper if there are any issues with this version connected to azure, and indeed there is one documented in the azure docs that hits what you observed perfectly!
please try to disable GSS explicitly in the connect string, so like this:

jdbc:postgresql://xxxxx.postgres.database.azure.com:5432/xxxx?gssEncMode=disable

1 Like

Hi, on top of the workaround pointed out by Tobias, we plan to upgrade the JDBC version used for the next versions. Ticket is tracked down here.

Thanks @Jos_Wilbrink for reporting the issue!

1 Like

@Tobias_Trabelsi @pierreguillot
Great!
Thanks for the feedback. I will use the workaround for now.

Hi,
I had the same problem when upgrading from SonarQube Community Edition Release 8.4.2, no Docker. It is using Azure PostgreSQL as well. I spent some time until finding the post here. I applied the workaround and everything went back to normal. Can you put this information on the Release Upgrade Notes? It will save time for a lot of people.
Thanks.

1 Like

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