Skip to content

Commit

Permalink
addressed at SqlServiceStub instead of the native layer
Browse files Browse the repository at this point in the history
  • Loading branch information
t-horikawa committed Sep 4, 2023
1 parent e18d0f7 commit 8b90cc2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
11 changes: 6 additions & 5 deletions modules/ipc/src/main/native/src/wireJNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ JNIEXPORT void JNICALL Java_com_tsurugidb_tsubakuro_channel_ipc_IpcLink_closeNat
session_wire_container* swc = reinterpret_cast<session_wire_container*>(static_cast<std::uintptr_t>(handle));

if (swc != nullptr) {
swc->get_request_wire().disconnect();
swc->get_response_wire().close();
}
}
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -285,10 +285,11 @@ JNIEXPORT void JNICALL Java_com_tsurugidb_tsubakuro_channel_ipc_sql_ResultSetWir
session_wire_container::resultset_wires_container* rwc = reinterpret_cast<session_wire_container::resultset_wires_container*>(static_cast<std::uintptr_t>(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;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
}

Expand Down Expand Up @@ -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);
}
}
}

Expand Down Expand Up @@ -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);
}
}
}

Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 8b90cc2

Please sign in to comment.