eclipse-vertx / vertx-sql-client

High performance reactive SQL Client written in Java
Apache License 2.0
894 stars 200 forks source link

Connection in the pool closed by the database won't be removed from the available connections #63

Closed vietj closed 6 years ago

mostafa-korkar1 commented 1 year ago

at io.vertx.core.impl.future.FutureImpl$2.onFailure(FutureImpl.java:117) at io.vertx.core.impl.future.FutureImpl$ListenerArray.onFailure(FutureImpl.java:268) at io.vertx.core.impl.future.FutureBase.emitFailure(FutureBase.java:75) at io.vertx.core.impl.future.FutureImpl.tryFail(FutureImpl.java:230) at io.vertx.core.impl.future.Mapping.onFailure(Mapping.java:45) at io.vertx.core.impl.future.FutureBase.emitFailure(FutureBase.java:75) at io.vertx.core.impl.future.FutureImpl.tryFail(FutureImpl.java:230) at io.vertx.core.impl.future.PromiseImpl.tryFail(PromiseImpl.java:23) at io.vertx.sqlclient.impl.QueryResultBuilder.tryFail(QueryResultBuilder.java:116) at io.vertx.core.Promise.fail(Promise.java:89) at io.vertx.core.Promise.handle(Promise.java:53) at io.vertx.core.Promise.handle(Promise.java:29) at io.vertx.core.impl.future.FutureImpl$3.onFailure(FutureImpl.java:153) at io.vertx.core.impl.future.FutureBase.emitFailure(FutureBase.java:75) at io.vertx.core.impl.future.FutureImpl.tryFail(FutureImpl.java:230) at io.vertx.core.impl.future.Composition$1.onFailure(Composition.java:66) at io.vertx.core.impl.future.FutureBase.emitFailure(FutureBase.java:75) at io.vertx.core.impl.future.FailedFuture.addListener(FailedFuture.java:98) at io.vertx.core.impl.future.Composition.onFailure(Composition.java:55) at io.vertx.core.impl.future.FutureBase.emitFailure(FutureBase.java:75) at io.vertx.core.impl.future.FutureImpl.tryFail(FutureImpl.java:230) at io.vertx.core.impl.future.PromiseImpl.tryFail(PromiseImpl.java:23) at io.vertx.core.impl.future.PromiseImpl.onFailure(PromiseImpl.java:54) at io.vertx.core.impl.future.PromiseImpl.handle(PromiseImpl.java:43) at io.vertx.core.impl.future.PromiseImpl.handle(PromiseImpl.java:23) at io.vertx.core.impl.EventLoopContext.emit(EventLoopContext.java:55) at io.vertx.core.impl.EventLoopContext.lambda$emit$1(EventLoopContext.java:62) at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:174) at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:167) at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:470) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:566) at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.base/java.lang.Thread.run(Thread.java:833)

May 09, 2023 11:59:11 PM com.coral.bookstore.service.BookHandler$Companion$buildErrorResponse$1 invoke
SEVERE: buildErrorResponse - Error : io.vertx.core.impl.NoStackTraceThrowable: Pool closed

mostafa-korkar1 commented 1 year ago

my DB Connection class as following:

` class DBConnection {

private val logger = Logger.getLogger(DBConnection::class.java.name)

fun pgPool(vertx : Vertx): PgPool { val context: Context = vertx.orCreateContext val activeProfile : String = context.config().getString("active_profile", "TEST") logger.info("DBConnection - active Profile : ".plus(activeProfile)) lateinit var config: JsonObject lateinit var connectOptions : PgConnectOptions lateinit var poolOptions : PoolOptions if (activeProfile.equals("DEV")) { config = vertx.fileSystem().readFileBlocking("DB_Connection.json").toJsonObject() connectOptions = PgConnectOptions() .setPort(config.getInteger("port")) .setHost(config.getString("host")) .setDatabase(config.getString("database")) .setUser(config.getString("user")) .setPassword(config.getString("password")) // Pool Options poolOptions = PoolOptions().setMaxSize(config.getInteger("max_pool_size")).setShared(true) }else { connectOptions = PgConnectOptions.fromUri(context.config().getString("db.uri")) .setUser(context.config().getString("db.username")) .setPassword(context.config().getString("db.password")) poolOptions = PoolOptions().setMaxSize(context.config().getInteger("max_pool_size")).setShared(true) }

// Create the pool from the data object
return PgPool.pool(vertx, connectOptions, poolOptions)

} } `

mostafa-korkar1 commented 1 year ago

my Test class as following :

` @Testcontainers @ExtendWith(VertxExtension::class) class MainVerticleIntegrationTest {

private val logger = Logger.getLogger(MainVerticleIntegrationTest::class.java.name) private val deploymentOptions: DeploymentOptions = DeploymentOptions()

@BeforeEach fun deploy_verticle(vertx: Vertx, testContext: VertxTestContext) { val dbUri = postgresqlContainer.jdbcUrl.substringAfter("jdbc:") deploymentOptions.config = jsonObjectOf( "db.uri" to dbUri, "db.username" to DB_USERNAME, "db.password" to DB_PASSWORD, "max_poolsize" to 5 ) vertx.deployVerticle(MainVerticle(), deploymentOptions, testContext.succeeding { -> testContext.completeNow() }) }

@Test fun test() { assertThat(postgresqlContainer.isRunning).isTrue }

@Test @DisplayName("test_return_all_books") fun test_return_all_books(vertx: Vertx, testContext: VertxTestContext) {

var bookInfoToBeMatched = BookInfo(1, "zxc3", "Test 1", 52)
var client: HttpClient = vertx.createHttpClient()
client.request(HttpMethod.GET, 8090, "localhost", "/books")
  .compose(HttpClientRequest::send)
  .compose(HttpClientResponse::body)
  .onSuccess { body ->
    testContext.verify {
      val bookInfos = toList(body.toJsonArray())
      assertThat(bookInfos).anyMatch { it -> checkingBookMatching(it, bookInfoToBeMatched) }
    }
    testContext.completeNow()
  }
  .onFailure { failure -> testContext.failNow(failure) };

} companion object { private const val DB_NAME = "coral_book_store" private const val DB_USERNAME = "coral" private const val DB_PASSWORD = "coral"

@Container
private var postgresqlContainer: PostgreSQLContainer<Nothing> = PostgreSQLContainer<Nothing>("postgres:15")
  .apply {
    withDatabaseName(DB_NAME)
    withUsername(DB_USERNAME)
    withPassword(DB_PASSWORD)
  }

} } `