You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by we...@apache.org on 2020/05/04 20:09:06 UTC

[hadoop] branch trunk updated: HDFS-15270. Account for *env == NULL in hdfsThreadDestructor (#1951)

This is an automated email from the ASF dual-hosted git repository.

weichiu pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/hadoop.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 1996351  HDFS-15270. Account for *env == NULL in hdfsThreadDestructor (#1951)
1996351 is described below

commit 1996351b0b7be6866eda73223ab6ef1ec78d30cd
Author: Babneet Singh <ba...@users.noreply.github.com>
AuthorDate: Mon May 4 16:08:53 2020 -0400

    HDFS-15270. Account for *env == NULL in hdfsThreadDestructor (#1951)
    
    OpenJ9 JVM properly terminates the thread before hdfsThreadDestructor is
    invoked. JNIEnv is a mirror of J9VMThread in OpenJ9. After proper thread
    termination, accessing JNIEnv in hdfsThreadDestructor (*env)->GetJavaVM,
    yields a SIGSEGV since *env is NULL after thread cleanup is performed.
    
    The main purpose of hdfsThreadDestructor is to invoke
    DetachCurrentThread, which performs thread cleanup in OpenJ9. Since
    OpenJ9 performs thread cleanup before hdfsThreadDestructor is invoked,
    hdfsThreadDestructor should account for *env == NULL and skip
    DetachCurrentThread.
    
    Signed-off-by: Babneet Singh <sb...@ca.ibm.com>
---
 .../src/main/native/libhdfs/os/posix/thread_local_storage.c           | 2 +-
 .../src/main/native/libhdfs/os/windows/thread_local_storage.c         | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/os/posix/thread_local_storage.c b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/os/posix/thread_local_storage.c
index a0f26c6..1b6dafa 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/os/posix/thread_local_storage.c
+++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/os/posix/thread_local_storage.c
@@ -53,7 +53,7 @@ void hdfsThreadDestructor(void *v)
   char thr_name[MAXTHRID];
 
   /* Detach the current thread from the JVM */
-  if (env) {
+  if ((env != NULL) && (*env != NULL)) {
     ret = (*env)->GetJavaVM(env, &vm);
 
     if (ret != 0) {
diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/os/windows/thread_local_storage.c b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/os/windows/thread_local_storage.c
index a6f48fd..f7abc89 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/os/windows/thread_local_storage.c
+++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/os/windows/thread_local_storage.c
@@ -46,10 +46,10 @@ static void detachCurrentThreadFromJvm()
   if (threadLocalStorageGet(&state) || !state) {
     return;
   }
-  if (!state->env) {
+  env = state->env;
+  if ((env == NULL) || (*env == NULL)) {
     return;
   }
-  env = state->env;
   ret = (*env)->GetJavaVM(env, &vm);
   if (ret) {
     fprintf(stderr,


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org