Skip to content

Commit

Permalink
[fix](jni) avoid BE crash and NPE when close paimon reader
Browse files Browse the repository at this point in the history
  • Loading branch information
morningman committed Nov 16, 2023
1 parent 343d581 commit 733d5ea
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 3 additions & 3 deletions be/src/vec/exec/jni_connector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ Status JniConnector::open(RuntimeState* state, RuntimeProfile* profile) {
RETURN_IF_ERROR(_init_jni_scanner(env, batch_size));
// Call org.apache.doris.common.jni.JniScanner#open
env->CallVoidMethod(_jni_scanner_obj, _jni_scanner_open);
_scanner_opened = true;
RETURN_ERROR_IF_EXC(env);
return Status::OK();
}
Expand Down Expand Up @@ -167,7 +168,7 @@ Status JniConnector::close() {
if (!_closed) {
JNIEnv* env = nullptr;
RETURN_IF_ERROR(JniUtil::GetJNIEnv(&env));
if (_scanner_initialized) {
if (_scanner_opened) {
// update scanner metrics
for (const auto& metric : get_statistics(env)) {
std::vector<std::string> type_and_name = split(metric.first, ":");
Expand Down Expand Up @@ -204,7 +205,7 @@ Status JniConnector::close() {
_closed = true;
jthrowable exc = (env)->ExceptionOccurred();
if (exc != nullptr) {
LOG(FATAL) << "Failed to release jni resource: "
LOG(WARNING) << "Failed to release jni resource: "
<< JniUtil::GetJniExceptionMsg(env).to_string();
}
}
Expand Down Expand Up @@ -241,7 +242,6 @@ Status JniConnector::_init_jni_scanner(JNIEnv* env, int batch_size) {
_jni_scanner_get_statistics =
env->GetMethodID(_jni_scanner_cls, "getStatistics", "()Ljava/util/Map;");
RETURN_IF_ERROR(JniUtil::LocalToGlobalRef(env, jni_scanner_obj, &_jni_scanner_obj));
_scanner_initialized = true;
env->DeleteLocalRef(jni_scanner_obj);
RETURN_ERROR_IF_EXC(env);
return Status::OK();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ private void parseRequiredTypes() {

@Override
public void close() throws IOException {
reader.close();
if (reader != null) {
reader.close();
}
}

@Override
Expand Down

0 comments on commit 733d5ea

Please sign in to comment.