{"action":"created","comment":{"url":"https://api.github.com/repos/caskdata/cdap/pulls/comments/59423435","id":59423435,"diff_hunk":"@@ -93,6 +97,35 @@ public ProgramRunner createSparkProgramRunner(Injector injector) {\n     }\n   }\n \n+  /**\n+   * Create a new instance of {@link ProgramRunner} for Spark from the given {@link Injector}.\n+   *\n+   * @param injector The Guice Injector for acquiring CDAP system instances\n+   * @param programRunnerClass the class of the ProgramRunner to create\n+   * @return a new instance of {@link ProgramRunner}.\n+   */\n+  private ProgramRunner createSparkProgramRunner(Injector injector, Class<?> programRunnerClass) throws Exception {\n+    // We cannot get the SparkProgramRunner instance from the Injector directly as the guice injector will\n+    // cache the class, leading to ClassLoader leakage\n+    for (Constructor<?> constructor : programRunnerClass.getDeclaredConstructors()) {\n+      // Find the @Inject constructor\n+      if (!constructor.isAnnotationPresent(Inject.class)) {\n+        continue;\n+      }\n+      constructor.setAccessible(true);\n+\n+      // Acquire the instances for each parameter for the constructor\n+      Type[] paramTypes = constructor.getGenericParameterTypes();\n+      Object[] args = new Object[paramTypes.length];\n+      int i = 0;\n+      for (Type paramType : paramTypes) {\n+        args[i++] = injector.getInstance(Key.get(paramType));","path":"cdap-spark-core/src/main/java/co/cask/cdap/app/runtime/spark/SparkProgramRuntimeProvider.java","position":49,"original_position":49,"commit_id":"c337b4c266017ca00aceaed126d5021a8a2a683c","original_commit_id":"c337b4c266017ca00aceaed126d5021a8a2a683c","user":{"login":"chtyim","id":885032,"avatar_url":"https://avatars.githubusercontent.com/u/885032?v=3","gravatar_id":"","url":"https://api.github.com/users/chtyim","html_url":"https://github.com/chtyim","followers_url":"https://api.github.com/users/chtyim/followers","following_url":"https://api.github.com/users/chtyim/following{/other_user}","gists_url":"https://api.github.com/users/chtyim/gists{/gist_id}","starred_url":"https://api.github.com/users/chtyim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chtyim/subscriptions","organizations_url":"https://api.github.com/users/chtyim/orgs","repos_url":"https://api.github.com/users/chtyim/repos","events_url":"https://api.github.com/users/chtyim/events{/privacy}","received_events_url":"https://api.github.com/users/chtyim/received_events","type":"User","site_admin":false},"body":"It doesn't because the SparkProgramRunner only takes parameters that come from the CDAP system, hence through the CDAP system classloader. Hum, given that said, probably I should check the classloader of the `paramType` to decide if I can get it from injector directly or have to do instantiation recursively using this method.","created_at":"2016-04-12T18:01:34Z","updated_at":"2016-04-12T18:01:34Z","html_url":"https://github.com/caskdata/cdap/pull/5499#discussion_r59423435","pull_request_url":"https://api.github.com/repos/caskdata/cdap/pulls/5499","_links":{"self":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/comments/59423435"},"html":{"href":"https://github.com/caskdata/cdap/pull/5499#discussion_r59423435"},"pull_request":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/5499"}}},"pull_request":{"url":"https://api.github.com/repos/caskdata/cdap/pulls/5499","id":65874490,"html_url":"https://github.com/caskdata/cdap/pull/5499","diff_url":"https://github.com/caskdata/cdap/pull/5499.diff","patch_url":"https://github.com/caskdata/cdap/pull/5499.patch","issue_url":"https://api.github.com/repos/caskdata/cdap/issues/5499","number":5499,"state":"open","locked":false,"title":"(CDAP-5530) (CDAP-5547) Fix Spark ClassLoader and memory leakage","user":{"login":"chtyim","id":885032,"avatar_url":"https://avatars.githubusercontent.com/u/885032?v=3","gravatar_id":"","url":"https://api.github.com/users/chtyim","html_url":"https://github.com/chtyim","followers_url":"https://api.github.com/users/chtyim/followers","following_url":"https://api.github.com/users/chtyim/following{/other_user}","gists_url":"https://api.github.com/users/chtyim/gists{/gist_id}","starred_url":"https://api.github.com/users/chtyim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chtyim/subscriptions","organizations_url":"https://api.github.com/users/chtyim/orgs","repos_url":"https://api.github.com/users/chtyim/repos","events_url":"https://api.github.com/users/chtyim/events{/privacy}","received_events_url":"https://api.github.com/users/chtyim/received_events","type":"User","site_admin":false},"body":"- Spark is not designed for running multiple times inside the same VM, hence it's not doing proper cleanup.\r\n  Extra cleanup steps are added\r\n  - Shutdown the jetty server that Spark uses as file server (SPARK-14513)\r\n  - Stop the QueuedThreadPool(s) used by the jetty server that Spark uses as file server and WebUI (SPARK-14513)\r\n  - Remove the shutdown hook from ShutdownHookManager\r\n  - Invalid the LoadingCache of class constructor in BeanIntrospector\r\n  - Patch the akka.remote.Remoting code for fixing akka thread leak bug https://github.com/akka/akka/issues/17729\r\n    - Done through simple bytecode replacement\r\n\r\n- Also there are CDAP spark-core fixes related to ClassLoader leakage\r\n  - Clear the SparkListener list when Spark job finished\r\n  - Don't use guice Injector to instantiate SparkProgramRunner directly, as guice will cache the class\r\n\r\n- Fixed CDAP-5547 by defining the class using parent method so that package is also defined\r\n\r\n- Also an improvement to the AbstractSparkSubmitter to make sure the Spark job is finished before returning control back to SparkRuntimeService","created_at":"2016-04-09T07:58:03Z","updated_at":"2016-04-12T18:01:34Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c1a556c5df449adb31fcf452db8b33ace729f097","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/caskdata/cdap/pulls/5499/commits","review_comments_url":"https://api.github.com/repos/caskdata/cdap/pulls/5499/comments","review_comment_url":"https://api.github.com/repos/caskdata/cdap/pulls/comments{/number}","comments_url":"https://api.github.com/repos/caskdata/cdap/issues/5499/comments","statuses_url":"https://api.github.com/repos/caskdata/cdap/statuses/c337b4c266017ca00aceaed126d5021a8a2a683c","head":{"label":"caskdata:feature/fix-spark-cl-leak","ref":"feature/fix-spark-cl-leak","sha":"c337b4c266017ca00aceaed126d5021a8a2a683c","user":{"login":"caskdata","id":8123023,"avatar_url":"https://avatars.githubusercontent.com/u/8123023?v=3","gravatar_id":"","url":"https://api.github.com/users/caskdata","html_url":"https://github.com/caskdata","followers_url":"https://api.github.com/users/caskdata/followers","following_url":"https://api.github.com/users/caskdata/following{/other_user}","gists_url":"https://api.github.com/users/caskdata/gists{/gist_id}","starred_url":"https://api.github.com/users/caskdata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caskdata/subscriptions","organizations_url":"https://api.github.com/users/caskdata/orgs","repos_url":"https://api.github.com/users/caskdata/repos","events_url":"https://api.github.com/users/caskdata/events{/privacy}","received_events_url":"https://api.github.com/users/caskdata/received_events","type":"Organization","site_admin":false},"repo":{"id":22542759,"name":"cdap","full_name":"caskdata/cdap","owner":{"login":"caskdata","id":8123023,"avatar_url":"https://avatars.githubusercontent.com/u/8123023?v=3","gravatar_id":"","url":"https://api.github.com/users/caskdata","html_url":"https://github.com/caskdata","followers_url":"https://api.github.com/users/caskdata/followers","following_url":"https://api.github.com/users/caskdata/following{/other_user}","gists_url":"https://api.github.com/users/caskdata/gists{/gist_id}","starred_url":"https://api.github.com/users/caskdata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caskdata/subscriptions","organizations_url":"https://api.github.com/users/caskdata/orgs","repos_url":"https://api.github.com/users/caskdata/repos","events_url":"https://api.github.com/users/caskdata/events{/privacy}","received_events_url":"https://api.github.com/users/caskdata/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/caskdata/cdap","description":"Cask Data Application Platform (CDAP)","fork":false,"url":"https://api.github.com/repos/caskdata/cdap","forks_url":"https://api.github.com/repos/caskdata/cdap/forks","keys_url":"https://api.github.com/repos/caskdata/cdap/keys{/key_id}","collaborators_url":"https://api.github.com/repos/caskdata/cdap/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/caskdata/cdap/teams","hooks_url":"https://api.github.com/repos/caskdata/cdap/hooks","issue_events_url":"https://api.github.com/repos/caskdata/cdap/issues/events{/number}","events_url":"https://api.github.com/repos/caskdata/cdap/events","assignees_url":"https://api.github.com/repos/caskdata/cdap/assignees{/user}","branches_url":"https://api.github.com/repos/caskdata/cdap/branches{/branch}","tags_url":"https://api.github.com/repos/caskdata/cdap/tags","blobs_url":"https://api.github.com/repos/caskdata/cdap/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/caskdata/cdap/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/caskdata/cdap/git/refs{/sha}","trees_url":"https://api.github.com/repos/caskdata/cdap/git/trees{/sha}","statuses_url":"https://api.github.com/repos/caskdata/cdap/statuses/{sha}","languages_url":"https://api.github.com/repos/caskdata/cdap/languages","stargazers_url":"https://api.github.com/repos/caskdata/cdap/stargazers","contributors_url":"https://api.github.com/repos/caskdata/cdap/contributors","subscribers_url":"https://api.github.com/repos/caskdata/cdap/subscribers","subscription_url":"https://api.github.com/repos/caskdata/cdap/subscription","commits_url":"https://api.github.com/repos/caskdata/cdap/commits{/sha}","git_commits_url":"https://api.github.com/repos/caskdata/cdap/git/commits{/sha}","comments_url":"https://api.github.com/repos/caskdata/cdap/comments{/number}","issue_comment_url":"https://api.github.com/repos/caskdata/cdap/issues/comments{/number}","contents_url":"https://api.github.com/repos/caskdata/cdap/contents/{+path}","compare_url":"https://api.github.com/repos/caskdata/cdap/compare/{base}...{head}","merges_url":"https://api.github.com/repos/caskdata/cdap/merges","archive_url":"https://api.github.com/repos/caskdata/cdap/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/caskdata/cdap/downloads","issues_url":"https://api.github.com/repos/caskdata/cdap/issues{/number}","pulls_url":"https://api.github.com/repos/caskdata/cdap/pulls{/number}","milestones_url":"https://api.github.com/repos/caskdata/cdap/milestones{/number}","notifications_url":"https://api.github.com/repos/caskdata/cdap/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/caskdata/cdap/labels{/name}","releases_url":"https://api.github.com/repos/caskdata/cdap/releases{/id}","deployments_url":"https://api.github.com/repos/caskdata/cdap/deployments","created_at":"2014-08-02T09:00:10Z","updated_at":"2016-04-11T15:07:31Z","pushed_at":"2016-04-12T17:46:29Z","git_url":"git://github.com/caskdata/cdap.git","ssh_url":"git@github.com:caskdata/cdap.git","clone_url":"https://github.com/caskdata/cdap.git","svn_url":"https://github.com/caskdata/cdap","homepage":"http://cdap.io","size":410724,"stargazers_count":112,"watchers_count":112,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":39,"mirror_url":null,"open_issues_count":10,"forks":39,"open_issues":10,"watchers":112,"default_branch":"release/3.4"}},"base":{"label":"caskdata:release/3.4","ref":"release/3.4","sha":"50652e07199eb874a26c6aca91e262fd7929c670","user":{"login":"caskdata","id":8123023,"avatar_url":"https://avatars.githubusercontent.com/u/8123023?v=3","gravatar_id":"","url":"https://api.github.com/users/caskdata","html_url":"https://github.com/caskdata","followers_url":"https://api.github.com/users/caskdata/followers","following_url":"https://api.github.com/users/caskdata/following{/other_user}","gists_url":"https://api.github.com/users/caskdata/gists{/gist_id}","starred_url":"https://api.github.com/users/caskdata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caskdata/subscriptions","organizations_url":"https://api.github.com/users/caskdata/orgs","repos_url":"https://api.github.com/users/caskdata/repos","events_url":"https://api.github.com/users/caskdata/events{/privacy}","received_events_url":"https://api.github.com/users/caskdata/received_events","type":"Organization","site_admin":false},"repo":{"id":22542759,"name":"cdap","full_name":"caskdata/cdap","owner":{"login":"caskdata","id":8123023,"avatar_url":"https://avatars.githubusercontent.com/u/8123023?v=3","gravatar_id":"","url":"https://api.github.com/users/caskdata","html_url":"https://github.com/caskdata","followers_url":"https://api.github.com/users/caskdata/followers","following_url":"https://api.github.com/users/caskdata/following{/other_user}","gists_url":"https://api.github.com/users/caskdata/gists{/gist_id}","starred_url":"https://api.github.com/users/caskdata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caskdata/subscriptions","organizations_url":"https://api.github.com/users/caskdata/orgs","repos_url":"https://api.github.com/users/caskdata/repos","events_url":"https://api.github.com/users/caskdata/events{/privacy}","received_events_url":"https://api.github.com/users/caskdata/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/caskdata/cdap","description":"Cask Data Application Platform (CDAP)","fork":false,"url":"https://api.github.com/repos/caskdata/cdap","forks_url":"https://api.github.com/repos/caskdata/cdap/forks","keys_url":"https://api.github.com/repos/caskdata/cdap/keys{/key_id}","collaborators_url":"https://api.github.com/repos/caskdata/cdap/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/caskdata/cdap/teams","hooks_url":"https://api.github.com/repos/caskdata/cdap/hooks","issue_events_url":"https://api.github.com/repos/caskdata/cdap/issues/events{/number}","events_url":"https://api.github.com/repos/caskdata/cdap/events","assignees_url":"https://api.github.com/repos/caskdata/cdap/assignees{/user}","branches_url":"https://api.github.com/repos/caskdata/cdap/branches{/branch}","tags_url":"https://api.github.com/repos/caskdata/cdap/tags","blobs_url":"https://api.github.com/repos/caskdata/cdap/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/caskdata/cdap/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/caskdata/cdap/git/refs{/sha}","trees_url":"https://api.github.com/repos/caskdata/cdap/git/trees{/sha}","statuses_url":"https://api.github.com/repos/caskdata/cdap/statuses/{sha}","languages_url":"https://api.github.com/repos/caskdata/cdap/languages","stargazers_url":"https://api.github.com/repos/caskdata/cdap/stargazers","contributors_url":"https://api.github.com/repos/caskdata/cdap/contributors","subscribers_url":"https://api.github.com/repos/caskdata/cdap/subscribers","subscription_url":"https://api.github.com/repos/caskdata/cdap/subscription","commits_url":"https://api.github.com/repos/caskdata/cdap/commits{/sha}","git_commits_url":"https://api.github.com/repos/caskdata/cdap/git/commits{/sha}","comments_url":"https://api.github.com/repos/caskdata/cdap/comments{/number}","issue_comment_url":"https://api.github.com/repos/caskdata/cdap/issues/comments{/number}","contents_url":"https://api.github.com/repos/caskdata/cdap/contents/{+path}","compare_url":"https://api.github.com/repos/caskdata/cdap/compare/{base}...{head}","merges_url":"https://api.github.com/repos/caskdata/cdap/merges","archive_url":"https://api.github.com/repos/caskdata/cdap/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/caskdata/cdap/downloads","issues_url":"https://api.github.com/repos/caskdata/cdap/issues{/number}","pulls_url":"https://api.github.com/repos/caskdata/cdap/pulls{/number}","milestones_url":"https://api.github.com/repos/caskdata/cdap/milestones{/number}","notifications_url":"https://api.github.com/repos/caskdata/cdap/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/caskdata/cdap/labels{/name}","releases_url":"https://api.github.com/repos/caskdata/cdap/releases{/id}","deployments_url":"https://api.github.com/repos/caskdata/cdap/deployments","created_at":"2014-08-02T09:00:10Z","updated_at":"2016-04-11T15:07:31Z","pushed_at":"2016-04-12T17:46:29Z","git_url":"git://github.com/caskdata/cdap.git","ssh_url":"git@github.com:caskdata/cdap.git","clone_url":"https://github.com/caskdata/cdap.git","svn_url":"https://github.com/caskdata/cdap","homepage":"http://cdap.io","size":410724,"stargazers_count":112,"watchers_count":112,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":39,"mirror_url":null,"open_issues_count":10,"forks":39,"open_issues":10,"watchers":112,"default_branch":"release/3.4"}},"_links":{"self":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/5499"},"html":{"href":"https://github.com/caskdata/cdap/pull/5499"},"issue":{"href":"https://api.github.com/repos/caskdata/cdap/issues/5499"},"comments":{"href":"https://api.github.com/repos/caskdata/cdap/issues/5499/comments"},"review_comments":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/5499/comments"},"review_comment":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/5499/commits"},"statuses":{"href":"https://api.github.com/repos/caskdata/cdap/statuses/c337b4c266017ca00aceaed126d5021a8a2a683c"}}}}