question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NullPointerException when PostgreSQL is down after connecting

See original GitHub issue

I don’t know how to reproduce 100% of the cases. But I’m trying vertx and this postgresql driver and what I’m trying to see is the behavior of the application when it’s running but for some reason loses connection to PostgreSQL.

After the application is up and running, I kill my local PostgreSQL that is running inside of docker and in some situations I get a NullPointerException coming from inside of the reactive-pg-client lib.

This is the code:

suspend fun main(args: Array<String>) {
    val vertx = Vertx.vertx()

    // Pool options
    var options = pgPoolOptionsOf(
            port = 5432,
            host = "localhost",
            database = "client_data_management",
            user = "client-service",
            password = "client-service",
            connectTimeout = 5,
            reconnectInterval = 5,
            reconnectAttempts = 10,
            maxSize = 5)

    try {
        val pgConnection = PgClient.connectAwait(vertx, options)

        val clientEntityRepository = ClientEntityRepositoryPostgreSQL(pgConnection)

        val router = Router.router(vertx)

        router.get("/").handler { httpRequest ->
            GlobalScope.launch(vertx.dispatcher()) {
                clientEntityRepository.findAll().forEach {
                    httpRequest.response().end(it.toString())
                }
            }
        }.failureHandler {
            it.failure().printStackTrace()
            it.response().end("error")
        }

        vertx.createHttpServer()
                .requestHandler(router::accept)
                .listenAwait(8080)

    } catch (e: Exception) {
        println("exception")
        vertx.close()
    }
}
java.lang.NullPointerException
	at io.reactiverse.pgclient.impl.codec.decoder.MessageDecoder.decodeError(MessageDecoder.java:253)
	at io.reactiverse.pgclient.impl.codec.decoder.MessageDecoder.decodeMessage(MessageDecoder.java:142)
	at io.reactiverse.pgclient.impl.codec.decoder.MessageDecoder.channelRead(MessageDecoder.java:122)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965)
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163)
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:644)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:579)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:496)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:458)
	at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:897)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.base/java.lang.Thread.run(Thread.java:834)
Exception in thread "vert.x-eventloop-thread-0" io.vertx.core.VertxException: Connection not open CLOSED
	at io.reactiverse.pgclient.impl.SocketConnection.schedule(SocketConnection.java:229)
	at io.reactiverse.pgclient.impl.PgConnectionImpl.schedule(PgConnectionImpl.java:67)
	at io.reactiverse.pgclient.impl.PgConnectionImpl.schedule(PgConnectionImpl.java:59)
	at io.reactiverse.pgclient.impl.PgClientBase.query(PgClientBase.java:48)
	at io.reactiverse.pgclient.impl.PgClientBase.query(PgClientBase.java:38)
	at io.reactiverse.pgclient.impl.PgConnectionImpl.query(PgConnectionImpl.java:26)
	at xxx.ClientEntityRepositoryPostgreSQL$findAll$result$1.invoke(ClientRepository.kt:28)
	at xxx.ClientEntityRepositoryPostgreSQL$findAll$result$1.invoke(ClientRepository.kt:11)
	at io.vertx.kotlin.coroutines.VertxCoroutineKt.awaitEvent(VertxCoroutine.kt:66)
	at io.vertx.kotlin.coroutines.VertxCoroutineKt.awaitResult(VertxCoroutine.kt:96)
	at xxx.ClientEntityRepositoryPostgreSQL.findAll(ClientRepository.kt:28)
	at xxx.AppKt$main$2$1.invokeSuspend(App.kt:42)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:238)
	at io.vertx.kotlin.coroutines.VertxCoroutineExecutor.execute(VertxCoroutine.kt:230)
	at kotlinx.coroutines.ExecutorCoroutineDispatcherBase.dispatch(Executors.kt:64)
	at kotlinx.coroutines.DispatchedKt.resumeCancellable(Dispatched.kt:413)
	at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:25)
	at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:109)
	at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:154)
	at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:54)
	at kotlinx.coroutines.BuildersKt.launch(Unknown Source)
	at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(Builders.common.kt:47)
	at kotlinx.coroutines.BuildersKt.launch$default(Unknown Source)
	at xxx.AppKt$main$2.handle(App.kt:40)
	at xxx.AppKt$main$2.handle(App.kt)
	at io.vertx.ext.web.impl.RouteImpl.handleContext(RouteImpl.java:227)
	at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:121)
	at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:134)
	at io.vertx.ext.web.impl.RouterImpl.handle(RouterImpl.java:80)
	at io.vertx.ext.web.impl.RouterImpl.handle(RouterImpl.java:41)
	at io.vertx.ext.web.Router.accept(Router.java:64)
	at xxx.AppKt$main$4.invoke(App.kt:57)
	at xxx.AppKt$main$4.invoke(App.kt)
	at xxx.AppKt$sam$io_vertx_core_Handler$0.handle(App.kt)
	at io.vertx.core.http.impl.WebSocketRequestHandler.handle(WebSocketRequestHandler.java:50)
	at io.vertx.core.http.impl.WebSocketRequestHandler.handle(WebSocketRequestHandler.java:32)
	at io.vertx.core.http.impl.HttpServerRequestImpl.handleBegin(HttpServerRequestImpl.java:150)
	at io.vertx.core.http.impl.Http1xServerConnection.handleMessage(Http1xServerConnection.java:129)
	at io.vertx.core.net.impl.ConnectionBase.handleRead(ConnectionBase.java:390)
	at io.vertx.core.impl.ContextImpl.executeTask(ContextImpl.java:320)
	at io.vertx.core.impl.EventLoopContext.execute(EventLoopContext.java:43)
	at io.vertx.core.impl.ContextImpl.executeFromIO(ContextImpl.java:188)
	at io.vertx.core.net.impl.VertxHandler.channelRead(VertxHandler.java:174)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
	at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86)
	at io.netty.handler.codec.http.websocketx.extensions.WebSocketServerExtensionHandler.channelRead(WebSocketServerExtensionHandler.java:102)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
	at io.vertx.core.http.impl.Http1xUpgradeToH2CHandler.channelRead(Http1xUpgradeToH2CHandler.java:98)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
	at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:323)
	at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:297)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
	at io.vertx.core.http.impl.Http1xOrH2CHandler.end(Http1xOrH2CHandler.java:61)
	at io.vertx.core.http.impl.Http1xOrH2CHandler.channelRead(Http1xOrH2CHandler.java:38)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965)
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163)
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:644)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:579)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:496)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:458)
	at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:897)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.base/java.lang.Thread.run(Thread.java:834)```

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Globegittercommented, Sep 17, 2019

Will set something up.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NullPointerException caused by not accessing database from ...
I understand the problem, it is basically I was trying to reach Connection object that is null. I use static objects for accessing...
Read more >
java.lang.NullPointerException - PostgreSQL
most appropriate. I've got a database up and running under PostgreSQL called kwn. When I try to use the following Java code to...
Read more >
Java NullPointerException - Detect, Fix, and Best Practices
When we run the above program, it throws the following NullPointerException error message. Exception in thread "main" java.lang.
Read more >
Wildfly NullPointerException - Configuring the server - Keycloak
Hello, I am trying to deploy Keycloak using a helm chart provided by code centric at: https://codecentric.github.io/helm-charts this method ...
Read more >
Fix list for IBM WebSphere Application Server V8.5
Default Messaging Component, PH45134, CWSIJ0047E thrown after connection to ... PH44602, NullPointerException in WebSphere socket factory in 8.5.5.21 and ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found