Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 11CCB200C8F for ; Fri, 26 May 2017 07:28:09 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 1053F160BD5; Fri, 26 May 2017 05:28:09 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 53217160BCA for ; Fri, 26 May 2017 07:28:08 +0200 (CEST) Received: (qmail 54893 invoked by uid 500); 26 May 2017 05:28:07 -0000 Mailing-List: contact hdfs-issues-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list hdfs-issues@hadoop.apache.org Received: (qmail 54875 invoked by uid 99); 26 May 2017 05:28:07 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 26 May 2017 05:28:07 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id B29D5C0040 for ; Fri, 26 May 2017 05:28:06 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -100.002 X-Spam-Level: X-Spam-Status: No, score=-100.002 tagged_above=-999 required=6.31 tests=[RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id xk2z1yt0nheF for ; Fri, 26 May 2017 05:28:05 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id 182F75FB2C for ; Fri, 26 May 2017 05:28:05 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 8C062E0BDF for ; Fri, 26 May 2017 05:28:04 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 2267521B57 for ; Fri, 26 May 2017 05:28:04 +0000 (UTC) Date: Fri, 26 May 2017 05:28:04 +0000 (UTC) From: "John Zhuge (JIRA)" To: hdfs-issues@hadoop.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (HDFS-11851) getGlobalJNIEnv() may deadlock if exception is thrown MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Fri, 26 May 2017 05:28:09 -0000 [ https://issues.apache.org/jira/browse/HDFS-11851?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16025830#comment-16025830 ] John Zhuge commented on HDFS-11851: ----------------------------------- Thanks for adding the unit test. Discovered the patch didn't compile on Mac because Mac has {{PTHREAD_RECURSIVE_MUTEX_INITIALIZER}} but not {{PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP}}. If we'd like to support Mac, there may be 2 choices: 1) #ifdef {code} diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/os/posix/mutexes.c b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/os/posix/mutexes.c index c4c2f262135..a4e0e46d4a9 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/os/posix/mutexes.c +++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/os/posix/mutexes.c @@ -22,7 +22,11 @@ #include mutex hdfsHashMutex = PTHREAD_MUTEX_INITIALIZER; -mutex jvmMutex = PTHREAD_MUTEX_INITIALIZER; +#if defined __APPLE__ && defined __MACH__ +mutex jvmMutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER; +#else +mutex jvmMutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; +#endif int mutexLock(mutex *m) { int ret = pthread_mutex_lock(m); {code} 2) Use {{pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_RECURSIVE);}} but this means we need to add a static initializer. > getGlobalJNIEnv() may deadlock if exception is thrown > ----------------------------------------------------- > > Key: HDFS-11851 > URL: https://issues.apache.org/jira/browse/HDFS-11851 > Project: Hadoop HDFS > Issue Type: Bug > Components: libhdfs > Affects Versions: 3.0.0-alpha3 > Reporter: Henry Robinson > Assignee: Sailesh Mukil > Priority: Blocker > Attachments: HDFS-11851.000.patch, HDFS-11851.001.patch, HDFS-11851.002.patch > > > HDFS-11529 introduced a deadlock into {{getGlobalJNIEnv()}} if an exception is thrown. {{getGlobalJNIEnv()}} holds {{jvmMutex}}, but {{printExceptionAndFree()}} will eventually try to acquire that lock in {{setTLSExceptionStrings()}}. > The exception might get caught from {{loadFileSystems}}: > {code} > jthr = invokeMethod(env, NULL, STATIC, NULL, > "org/apache/hadoop/fs/FileSystem", > "loadFileSystems", "()V"); > if (jthr) { > printExceptionAndFree(env, jthr, PRINT_EXC_ALL, "loadFileSystems"); > } > } > {code} > and here's the relevant parts of the stack trace from where I call this API in Impala, which uses {{libhdfs}}: > {code} > #0 __lll_lock_wait () at ../nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:135 > #1 0x00007ffff4a8d657 in _L_lock_909 () from /lib/x86_64-linux-gnu/libpthread.so.0 > #2 0x00007ffff4a8d480 in __GI___pthread_mutex_lock (mutex=0x47ce960 ) at ../nptl/pthread_mutex_lock.c:79 > #3 0x0000000002f06056 in mutexLock (m=) at /data/2/jenkins/workspace/impala-hadoop-dependency/hadoop/hadoop-hdfs-project/hadoop-hdfs/src/main/native/libhdfs/os/posix/mutexes.c:28 > #4 0x0000000002efe817 in setTLSExceptionStrings (rootCause=0x0, stackTrace=0x0) at /data/2/jenkins/workspace/impala-hadoop-dependency/hadoop/hadoop-hdfs-project/hadoop-hdfs/src/main/native/libhdfs/jni_helper.c:581 > #5 0x0000000002f065d7 in printExceptionAndFreeV (env=0x513c1e8, exc=0x508a8c0, noPrintFlags=, fmt=0x34349cf "loadFileSystems", ap=0x7fffffffb660) > at /data/2/jenkins/workspace/impala-hadoop-dependency/hadoop/hadoop-hdfs-project/hadoop-hdfs/src/main/native/libhdfs/exception.c:183 > #6 0x0000000002f0683d in printExceptionAndFree (env=, exc=, noPrintFlags=, fmt=) > at /data/2/jenkins/workspace/impala-hadoop-dependency/hadoop/hadoop-hdfs-project/hadoop-hdfs/src/main/native/libhdfs/exception.c:213 > #7 0x0000000002eff60f in getGlobalJNIEnv () at /data/2/jenkins/workspace/impala-hadoop-dependency/hadoop/hadoop-hdfs-project/hadoop-hdfs/src/main/native/libhdfs/jni_helper.c:463 > {code} -- This message was sent by Atlassian JIRA (v6.3.15#6346) --------------------------------------------------------------------- To unsubscribe, e-mail: hdfs-issues-unsubscribe@hadoop.apache.org For additional commands, e-mail: hdfs-issues-help@hadoop.apache.org