Elasticsearch Connection refused when using real database

Template for a good bug report, formatted with Markdown:

  • Sonarqube 8.0
  • When using postgres DB SonarQube fails to start.```rt#-1}{qCsXOqOaTiK28LQ89BHNDg}{127.0.0.1}{127.0.0.1:9001}], ignoring…
    jvm 1 | org.elasticsearch.transport.ConnectTransportException: [127.0.0.1:9001] connect_exception
    jvm 1 | at org.elasticsearch.transport.TcpTransport$ChannelsConnectedListener.onFailure(TcpTransport.java:1

jvm 1 | at org.elasticsearch.action.ActionListener.lambda$toBiConsumer$2(ActionListener.java:100)
jvm 1 | at org.elasticsearch.common.concurrent.CompletableContext.lambda$addListener$0(CompletableContext.j
ava:42)
jvm 1 | at java.base/java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:859)
jvm 1 | at java.base/java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:
837)
jvm 1 | at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:506)
jvm 1 | at java.base/java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:20
88)
jvm 1 | at org.elasticsearch.common.concurrent.CompletableContext.completeExceptionally(CompletableContext.
java:57)
jvm 1 | at org.elasticsearch.transport.netty4.Netty4TcpChannel.lambda$new$1(Netty4TcpChannel.java:72)
jvm 1 | at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:511)
jvm 1 | at io.netty.util.concurrent.DefaultPromise.notifyListeners0(DefaultPromise.java:504)
jvm 1 | at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:483)
jvm 1 | at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:424)
jvm 1 | at io.netty.util.concurrent.DefaultPromise.tryFailure(DefaultPromise.java:121)
jvm 1 | at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.fulfillConnectPromise(AbstractNioChann
el.java:327)
jvm 1 | at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:
343)
jvm 1 | at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:644)
jvm 1 | at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:591)
jvm 1 | at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:508)
jvm 1 | at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:470)
jvm 1 | at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:909)
jvm 1 | at java.base/java.lang.Thread.run(Thread.java:834)
jvm 1 | Caused by: io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: /127.0.0.1:90
01jvm 1 | at java.base/sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
jvm 1 | at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:779)
jvm 1 | at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:327)
jvm 1 | at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:
340)
jvm 1 | … 6 common frames omitted
jvm 1 | Caused by: java.net.ConnectException: Connection refused
jvm 1 | … 10 common frames omitted
wrapper | <-- Wrapper Stopped```

  • configured Postgres db connection details
    Start sonar server
  • none I’m aware of

When running with embedded database all is fine. Also I am running this on a google compute engine instance with cloud sql postgres instance

Production Elasticsearch bootstrap checks kick in when you connect to a non-embedded database. Have you checked all the logs in your $SONARQUBE_HOME/logs/ directory?

Colin

Thanks for the quick reply Colin, so from looking at the web logs it looks like the connection to postgres is the issue Caused by: java.lang.IllegalStateException: Can not connect to database. Please check connectivity and settings (see the properties pref ixed by 'sonar.jdbc.'). at org.sonar.db.DefaultDatabase.checkConnection(DefaultDatabase.java:119) at org.sonar.db.DefaultDatabase.start(DefaultDatabase.java:84) ... 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:2385) at org.apache.commons.dbcp2.BasicDataSource.createDataSource(BasicDataSource.java:2110) at org.apache.commons.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:1563) 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:116) ... 25 common frames omitted Caused by: org.postgresql.util.PSQLException: The connection attempt failed. at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:292) at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49) at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:195) at org.postgresql.Driver.makeConnection(Driver.java:454) at org.postgresql.Driver.connect(Driver.java:256) at org.apache.commons.dbcp2.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:53) at org.apache.commons.dbcp2.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:291) at org.apache.commons.dbcp2.BasicDataSource.validateConnectionFactory(BasicDataSource.java:2395) at org.apache.commons.dbcp2.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:2381) ... 30 common frames omitted Caused by: java.net.SocketTimeoutException: connect timed out at java.base/java.net.PlainSocketImpl.socketConnect(Native Method) at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:399) at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242) at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224) at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:403) at java.base/java.net.Socket.connect(Socket.java:609) at org.postgresql.core.PGStream.<init>(PGStream.java:70) at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:91) at org.postgresql.core.v3.Connect