vertx-sql-client icon indicating copy to clipboard operation
vertx-sql-client copied to clipboard

[PostgreSQL] Connection not open CLOSED

Open Sakura-Sv opened this issue 5 years ago • 0 comments

Questions

I try to use the postgresql client to insert some data to my db, but something unexcepted occured. This is the code where I have the problem:

suspend fun register(user: UserInfo): Boolean {
        val conn = pgPool.connection.await()
        val trans = conn.begin().await()
        val userSql = """
            INSERT INTO "user".info(username, truename, password)
            VALUES($1, $2, $3)
        """.trimIndent()
        val roleSql = """
            SELECT id FROM "user".role
            WHERE name = $1
        """.trimIndent()
        val userRoleSql = """
            INSERT INTO "user".user_role(username, role_id)
            VALUES($1, $2)
        """.trimIndent()
        return try {
            val userRes = conn.preparedQuery(userSql).execute(Tuple.of(user.username, user.name, user.password)).await().rowCount() == 1
            val roleRes = conn.preparedQuery(roleSql).execute(Tuple.of(DEFAULT_USER_GROUP)).await()
            val userRoleRes =
                conn.preparedQuery(userRoleSql).execute(Tuple.of(user.username, roleRes.firstOrNull()!!.getLong("id")))
                    .await().rowCount() == 1
            if (userRes && userRoleRes) {
                trans.commit().await()
                true
            } else {
                trans.rollback().await()
                false
            }
        } catch (e: Exception) {
            log.error(e.message)
            false
        }
    }

But when my program reached this position, the following error occurred:

io.vertx.core.VertxException: Connection not open CLOSED

How I get my connection pool:

val connectionOptions = PgConnectOptions()
      .setPort(pgSQLPort)
      .setHost(pgSQLHost)
      .setDatabase(pgSQLDatabase)
      .setUser(pgSQLUser)
      .setPassword(pgSQLPassword)
return PgPool.pool(connectionOptions, PoolOptions())

I tried to restart my postgresql service, but it did not help to improve the problem.

Version

  • vertx-pg-client:4.0.0.CR2
  • vertx-sql-client:4.0.0.CR2
  • OpenJDK 11
  • PostgreSQL 10.14, compiled by Visual C++ build 1800, 64-bit
  • Windows10 20H2

Stacktrace

java.io.IOException: connection reset by peer
	at java.base/sun.nio.ch.SocketDispatcher.read0(Native Method)
	at java.base/sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:43)
	at java.base/sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:276)
	at java.base/sun.nio.ch.IOUtil.read(IOUtil.java:233)
	at java.base/sun.nio.ch.IOUtil.read(IOUtil.java:223)
	at java.base/sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:358)
	at io.netty.buffer.PooledByteBuf.setBytes(PooledByteBuf.java:253)
	at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1133)
	at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:350)
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:148)
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:714)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:650)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:576)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
	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:834)
io.vertx.core.VertxException: Connection not open CLOSED
	at io.vertx.sqlclient.impl.SocketConnectionBase.doSchedule(SocketConnectionBase.java:159)
	at io.vertx.pgclient.impl.PgSocketConnection.doSchedule(PgSocketConnection.java:154)
	at io.vertx.sqlclient.impl.SocketConnectionBase.lambda$schedule$3(SocketConnectionBase.java:143)
	at io.vertx.core.impl.EventLoopContext.emit(EventLoopContext.java:52)
	at io.vertx.core.impl.EventLoopContext.lambda$emit$1(EventLoopContext.java:59)
	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute$$$capture(AbstractEventExecutor.java:164)
	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java)
	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:497)
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
	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:834)
2020-12-07 05:49:00.022 ERROR 15892 --- [ntloop-thread-0] c.sakura.by.examol.dao.user.UniUserDao   : connection reset by peer

Extra

The problem disappeared and the program worked well when I switched the version of the library back to 4.0.0.CR1. So I guess that some changes in CR2 caused the problem.

Sakura-Sv avatar Dec 07 '20 06:12 Sakura-Sv