From 8b90cc2ddf93a8ea260f35f6691b634787e8fa9c Mon Sep 17 00:00:00 2001 From: t-horikawa Date: Fri, 1 Sep 2023 23:43:44 +0900 Subject: [PATCH] addressed at SqlServiceStub instead of the native layer --- modules/ipc/src/main/native/src/wireJNI.cpp | 11 ++++--- .../tsubakuro/sql/impl/SqlServiceStub.java | 31 ++++++++++++++++--- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/modules/ipc/src/main/native/src/wireJNI.cpp b/modules/ipc/src/main/native/src/wireJNI.cpp index 354105b5..61f8d566 100644 --- a/modules/ipc/src/main/native/src/wireJNI.cpp +++ b/modules/ipc/src/main/native/src/wireJNI.cpp @@ -161,7 +161,6 @@ JNIEXPORT void JNICALL Java_com_tsurugidb_tsubakuro_channel_ipc_IpcLink_closeNat session_wire_container* swc = reinterpret_cast(static_cast(handle)); if (swc != nullptr) { - swc->get_request_wire().disconnect(); swc->get_response_wire().close(); } } @@ -178,6 +177,7 @@ JNIEXPORT void JNICALL Java_com_tsurugidb_tsubakuro_channel_ipc_IpcLink_destroyN if (swc != nullptr) { if (swc->is_deletable()) { + swc->get_request_wire().disconnect(); delete swc; } } @@ -285,10 +285,11 @@ JNIEXPORT void JNICALL Java_com_tsurugidb_tsubakuro_channel_ipc_sql_ResultSetWir session_wire_container::resultset_wires_container* rwc = reinterpret_cast(static_cast(handle)); if (rwc != nullptr) { - session_wire_container* envelope = rwc->get_envelope(); - if (envelope != nullptr) { - if (envelope->dispose_resultset_wire(rwc)) { - delete envelope; + session_wire_container* swc = rwc->get_envelope(); + if (swc != nullptr) { + if (swc->dispose_resultset_wire(rwc)) { + swc->get_request_wire().disconnect(); + delete swc; } } } diff --git a/modules/session/src/main/java/com/tsurugidb/tsubakuro/sql/impl/SqlServiceStub.java b/modules/session/src/main/java/com/tsurugidb/tsubakuro/sql/impl/SqlServiceStub.java index 2a1ed16e..94aa0d8e 100644 --- a/modules/session/src/main/java/com/tsurugidb/tsubakuro/sql/impl/SqlServiceStub.java +++ b/modules/session/src/main/java/com/tsurugidb/tsubakuro/sql/impl/SqlServiceStub.java @@ -67,6 +67,8 @@ public class SqlServiceStub implements SqlService { private Timeout closeTimeout = Timeout.DISABLED; + private boolean resourcesClosed = false; + /** * Creates a new instance. * @param session the current session @@ -132,7 +134,13 @@ public Transaction process(ByteBuffer payload) throws IOException, ServerExcepti } var transactionImpl = new TransactionImpl(detailResponse.getSuccess(), SqlServiceStub.this, resources); transactionImpl.setCloseTimeout(closeTimeout); - return resources.register(transactionImpl); + synchronized (resources) { + if (resourcesClosed) { + transactionImpl.close(); + throw new IOException("session already closed"); + } + return resources.register(transactionImpl); + } } } @@ -247,7 +255,13 @@ public PreparedStatement process(ByteBuffer payload) throws IOException, ServerE } var preparedStatementImpl = new PreparedStatementImpl(detailResponse.getPreparedStatementHandle(), SqlServiceStub.this, resources, request); preparedStatementImpl.setCloseTimeout(closeTimeout); - return resources.register(preparedStatementImpl); + synchronized (resources) { + if (resourcesClosed) { + preparedStatementImpl.close(); + throw new IOException("session already closed"); + } + return resources.register(preparedStatementImpl); + } } } @@ -511,7 +525,13 @@ public ResultSet process(Response response, Timeout timeout) throws IOException, } var resultSetImpl = new ResultSetImpl(resources, metadata, cursor, owner.release(), this, resultSetName, request); resultSetImpl.setCloseTimeout(closeTimeout); - return resources.register(resultSetImpl); + synchronized (resources) { + if (resourcesClosed) { + resultSetImpl.close(); + throw new IOException("session already closed"); + } + return resources.register(resultSetImpl); + } } } @@ -830,7 +850,10 @@ public void setCloseTimeout(Timeout timeout) { @Override public void close() throws ServerException, IOException, InterruptedException { LOG.trace("closing underlying resources"); //$NON-NLS-1$ - resources.close(); + synchronized (resources) { + resources.close(); + resourcesClosed = true; + } session.remove(this); }