[ 
https://issues.apache.org/jira/browse/FLINK-12620?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16849259#comment-16849259
 ] 

Mike Kaplinskiy edited comment on FLINK-12620 at 5/28/19 12:38 AM:
-------------------------------------------------------------------

Sure, here's an example deadlock that I see, attached. [^jstack_snippet.txt] 

Somewhere between those 2 threads is a class initialization deadlock. My hacky 
fix that I tried locally looks like this:
{code}
diff --git 
a/flink-core/src/main/java/org/apache/flink/util/InstantiationUtil.java 
b/flink-core/src/main/java/org/apache/flink/util/InstantiationUtil.java
index 644289133b..dc722c1db4 100644
--- a/flink-core/src/main/java/org/apache/flink/util/InstantiationUtil.java
+++ b/flink-core/src/main/java/org/apache/flink/util/InstantiationUtil.java
@@ -492,7 +492,7 @@ public final class InstantiationUtil {
                }
        }

-       public static <T> T readObjectFromConfig(Configuration config, String 
key, ClassLoader cl) throws IOException, ClassNotFoundException {
+       public static synchronized <T> T readObjectFromConfig(Configuration 
config, String key, ClassLoader cl) throws IOException, ClassNotFoundException {
                byte[] bytes = config.getBytes(key, null);
                if (bytes == null) {
                        return null;
{code}

That said, I'm not sure that it's the proper fix.


was (Author: mikekap):
Sure, here's an example deadlock that I see, attached. [^jstack_snippet.txt] 

Somewhere between those 3 threads is a class initialization deadlock. My hacky 
fix that I tried locally looks like this:
{code}
diff --git 
a/flink-core/src/main/java/org/apache/flink/util/InstantiationUtil.java 
b/flink-core/src/main/java/org/apache/flink/util/InstantiationUtil.java
index 644289133b..dc722c1db4 100644
--- a/flink-core/src/main/java/org/apache/flink/util/InstantiationUtil.java
+++ b/flink-core/src/main/java/org/apache/flink/util/InstantiationUtil.java
@@ -492,7 +492,7 @@ public final class InstantiationUtil {
                }
        }

-       public static <T> T readObjectFromConfig(Configuration config, String 
key, ClassLoader cl) throws IOException, ClassNotFoundException {
+       public static synchronized <T> T readObjectFromConfig(Configuration 
config, String key, ClassLoader cl) throws IOException, ClassNotFoundException {
                byte[] bytes = config.getBytes(key, null);
                if (bytes == null) {
                        return null;
{code}

That said, I'm not sure that it's the proper fix.

> Deadlock in task deserialization
> --------------------------------
>
>                 Key: FLINK-12620
>                 URL: https://issues.apache.org/jira/browse/FLINK-12620
>             Project: Flink
>          Issue Type: Bug
>    Affects Versions: 1.8.0
>            Reporter: Mike Kaplinskiy
>            Priority: Major
>         Attachments: jstack_snippet.txt
>
>
> When running a batch job, I ran into an issue where task deserialization 
> caused a deadlock. Specifically, if you have a static initialization 
> dependency graph that looks like this (these are all classes):
> {code:java}
> Task1 depends on A
>     A depends on B
>     B depends on C
>     C depends on B [cycle]
> Task2 depends on C{code}
> What seems to happen is a deadlock. Specifically, threads are started on the 
> task managers that simultaneously call BatchTask.instantiateUserCode on both 
> Task1 and Task2. This starts deserializing the classes and initializing them. 
> Here's the deadlock scenario, as a stack:
> {code:java}
> Time---->
> T1: [deserialize] -> Task1<clinit> -> A<clinit> -> B<clinit> -> (wait for 
> C<clinit>)
> T2: [deserialize] -> Task2<clinit>              -> C<clinit> -> (wait for 
> B<clinit>){code}
>  
> A similar scenario from the web: 
> [https://www.farside.org.uk/201510/deadlocks_in_java_class_initialisation] .
>  
> For my specific problem, I'm running into this within Clojure - 
> {{clojure.lang.RT}} has a dep on {{clojure.lang.Util}} which has a dep with 
> {{clojure.lang.Numbers}} which depends on {{clojure.lang.RT}} again. 
> Deserializing different clojure functions calls one or the other first which 
> deadlocks task managers.
>  
> I built a version of flink-core that had 
> {{org.apache.flink.util.InstantiationUtil.readObjectFromConfig}} 
> synchronized, but I'm not sure that it's the proper fix. I'm happy to submit 
> that as a patch, but I'm not familiar enough with the codebase to say that 
> it's the correct solution - ideally all Java class loading is synchronized, 
> but I'm not sure how to do that.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to