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 1, 2023
1 parent e18d0f7 commit 788cd14
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 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 closed = 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 (this) {
if (closed) {
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 (this) {
if (closed) {
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 (this) {
if (closed) {
resultSetImpl.close();
throw new IOException("session already closed");
}
return resources.register(resultSetImpl);
}
}
}

Expand Down Expand Up @@ -830,8 +850,11 @@ public void setCloseTimeout(Timeout timeout) {
@Override
public void close() throws ServerException, IOException, InterruptedException {
LOG.trace("closing underlying resources"); //$NON-NLS-1$
resources.close();
session.remove(this);
synchronized (this) {
resources.close();
session.remove(this);
closed = true;
}
}

private byte[] toDelimitedByteArray(SqlRequest.Request request) throws IOException {
Expand Down

0 comments on commit 788cd14

Please sign in to comment.