Skip to content

NullPointerException while using poll.withTransaction(TransactionPropagation.CONTEXT) and losing connection to the database #1447

Open
@NekiyXX

Description

@NekiyXX

Version

vert.x 4.5.8

Context

There is a NullPointerException in io.vertx.sqlclient when I try to create transaction with Propagation like: poll.withTransaction(TransactionPropagation.CONTEXT) {}

java.lang.NullPointerException: null at java.base/java.util.concurrent.ConcurrentHashMap.putVal(ConcurrentHashMap.java:1011) ~[?:?] at java.base/java.util.concurrent.ConcurrentHashMap.put(ConcurrentHashMap.java:1006) ~[?:?] at io.vertx.core.impl.ContextInternal.putLocal(ContextInternal.java:418) ~[vertx-core-4.5.8.jar:4.5.8] at io.vertx.sqlclient.impl.PoolImpl.lambda$startPropagatableConnection$5(PoolImpl.java:149) ~[vertx-sql-client-4.5.8.jar:4.5.8] at io.vertx.core.impl.future.FutureImpl$4.onFailure(FutureImpl.java:188) ~[vertx-core-4.5.8.jar:4.5.8] at io.vertx.core.impl.future.FutureImpl$ListenerArray.onFailure(FutureImpl.java:316) ~[vertx-core-4.5.8.jar:4.5.8] at io.vertx.core.impl.future.FutureBase.emitFailure(FutureBase.java:81) ~[vertx-core-4.5.8.jar:4.5.8] at io.vertx.core.impl.future.FutureImpl.tryFail(FutureImpl.java:278) ~[vertx-core-4.5.8.jar:4.5.8] at io.vertx.core.impl.future.Mapping.onFailure(Mapping.java:45) ~[vertx-core-4.5.8.jar:4.5.8] at io.vertx.core.impl.future.FutureBase.emitFailure(FutureBase.java:81) ~[vertx-core-4.5.8.jar:4.5.8]

Steps to reproduce

This occurs if the transaction does not exist in the context and the connection to the database is lost.

  1. SqlConnection not found in context and we are going to the 192 line: "return startPropagatableConnection(this, function);"

Pool.java 192
image

  1. After that we try to get connection and put it in context in 149 line:

PoolImpl.java 149
image

  1. But handler.result() return null here because it is CaseHolder:
image This null result vertx try to set in context and we get NullPointer.

Extra

In our project we use vertx.exceptionHandler to caught an unhandled exception and shutdown the server if something goes wrong, in which case Kubernetes should start the pod again. So this nullpointer shutdown our server. Temporarily I added an exceptionHandler to the current vertx context to skip this error. But I think that vertx sql client should not try to set null in the vertx context.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions