Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disconnect IPC connection at IpcLink.closeNative() #323

Merged
merged 2 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions modules/ipc/src/main/native/include/udf_wires.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,7 @@ class session_wire_container
}
}

~session_wire_container() {
request_wire_.disconnect();
}
~session_wire_container() = default;

bool is_deletable() {
std::lock_guard<std::mutex> lock(mtx_set_);
Expand Down
10 changes: 6 additions & 4 deletions modules/ipc/src/main/native/src/wireJNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,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 @@ -284,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
Loading