You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2020/09/21 16:56:30 UTC

[GitHub] [nifi] turcsanyip opened a new pull request #4540: NIFI-7825: Support native library loading via absolute path

turcsanyip opened a new pull request #4540:
URL: https://github.com/apache/nifi/pull/4540


   Use an AspectJ aspect and agent to intercept the load native library calls
   at runtime, copy the native library file to temp folder and proceed with
   the newly created file in order to provide classloader isolation.
   
   https://issues.apache.org/jira/browse/NIFI-7825
   
   Thank you for submitting a contribution to Apache NiFi.
   
   Please provide a short description of the PR here:
   
   #### Description of PR
   
   _Enables X functionality; fixes bug NIFI-YYYY._
   
   In order to streamline the review of the contribution we ask you
   to ensure the following steps have been taken:
   
   ### For all changes:
   - [ ] Is there a JIRA ticket associated with this PR? Is it referenced 
        in the commit message?
   
   - [ ] Does your PR title start with **NIFI-XXXX** where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
   
   - [ ] Has your PR been rebased against the latest commit within the target branch (typically `main`)?
   
   - [ ] Is your initial contribution a single, squashed commit? _Additional commits in response to PR reviewer feedback should be made on this branch and pushed to allow change tracking. Do not `squash` or use `--force` when pushing to allow for clean monitoring of changes._
   
   ### For code changes:
   - [ ] Have you ensured that the full suite of tests is executed via `mvn -Pcontrib-check clean install` at the root `nifi` folder?
   - [ ] Have you written or updated unit tests to verify your changes?
   - [ ] Have you verified that the full build is successful on JDK 8?
   - [ ] Have you verified that the full build is successful on JDK 11?
   - [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)? 
   - [ ] If applicable, have you updated the `LICENSE` file, including the main `LICENSE` file under `nifi-assembly`?
   - [ ] If applicable, have you updated the `NOTICE` file, including the main `NOTICE` file found under `nifi-assembly`?
   - [ ] If adding new Properties, have you added `.displayName` in addition to .name (programmatic access) for each of the new properties?
   
   ### For documentation related changes:
   - [ ] Have you ensured that format looks appropriate for the output in which it is rendered?
   
   ### Note:
   Please ensure that once the PR is submitted, you check GitHub Actions CI for build issues and submit an update to your PR as soon as possible.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] bbende commented on pull request #4540: NIFI-7825: Support native library loading via absolute path

Posted by GitBox <gi...@apache.org>.
bbende commented on pull request #4540:
URL: https://github.com/apache/nifi/pull/4540#issuecomment-716799802


   Latest changes look good, thanks! Will merge


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] turcsanyip commented on a change in pull request #4540: NIFI-7825: Support native library loading via absolute path

Posted by GitBox <gi...@apache.org>.
turcsanyip commented on a change in pull request #4540:
URL: https://github.com/apache/nifi/pull/4540#discussion_r496900671



##########
File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-resources/src/main/resources/conf/bootstrap.conf
##########
@@ -66,6 +66,15 @@ java.arg.16=-Djavax.security.auth.useSubjectCredsOnly=true
 # Please see https://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_adminserver_config for configuration options.
 java.arg.17=-Dzookeeper.admin.enableServer=false
 
+# The following options configure a Java Agent to handle native library loading.
+# It is needed when a custom jar (eg. JDBC driver) has been configured on a component in the flow and this custom jar depends on a native library
+# and tries to load it by its absolute path (java.lang.System.load(String filename) method call).
+# Use this Java Agent only if you get "Native Library ... already loaded in another classloader" errors otherwise!
+#java.arg.18=-javaagent:./lib/aspectjweaver-${aspectj.version}.jar

Review comment:
       I double checked it and unfortunately the aspect class in `nifi-nar-utils.jar` depends on `aspectjrt.jar`.
   As `nifi-nar-utils.jar` is located in the lib folder and loaded by the system classloader, `aspectjrt.jar` must be on the system classpath too.
   And I did not want to separate the 2 AspectJ jars so I put `aspectjweaver.jar` to the lib folder.
   
   Options:
   1. leave it as it is now (both `aspectjrt.jar` and `aspectjweaver.jar` in the `lib` folder)
   2. leave `aspectjrt.jar` in `lib` and move `aspectjweaver.jar` to `lib/aspectj`
   3. find another place for the aspect class and move its `aspectjrt.jar` dependency there, move `aspectjweaver.jar` to `lib/aspectj`
   
   Option 2 seems to me a bit weird structure and one of the AspectJ jars is still on the system classpath.
   Option 3 could work but I would keep the native library loading stuff (`AbstractNativeLibHandlingClassLoader` and `LoadNativeLibAspect`) in the same module.
   
   So I would still vote for option 1.
   These jars have no effect if they are not referenced in our code / the agent is not turned on.
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] bbende commented on a change in pull request #4540: NIFI-7825: Support native library loading via absolute path

Posted by GitBox <gi...@apache.org>.
bbende commented on a change in pull request #4540:
URL: https://github.com/apache/nifi/pull/4540#discussion_r496806431



##########
File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-resources/src/main/resources/conf/bootstrap.conf
##########
@@ -66,6 +66,15 @@ java.arg.16=-Djavax.security.auth.useSubjectCredsOnly=true
 # Please see https://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_adminserver_config for configuration options.
 java.arg.17=-Dzookeeper.admin.enableServer=false
 
+# The following options configure a Java Agent to handle native library loading.
+# It is needed when a custom jar (eg. JDBC driver) has been configured on a component in the flow and this custom jar depends on a native library
+# and tries to load it by its absolute path (java.lang.System.load(String filename) method call).
+# Use this Java Agent only if you get "Native Library ... already loaded in another classloader" errors otherwise!
+#java.arg.18=-javaagent:./lib/aspectjweaver-${aspectj.version}.jar

Review comment:
       I think if we can do the `lib/aspectj` approach then that is the best option, anything we can do to avoid introducing additional dependencies to the system classpath is good.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] turcsanyip commented on a change in pull request #4540: NIFI-7825: Support native library loading via absolute path

Posted by GitBox <gi...@apache.org>.
turcsanyip commented on a change in pull request #4540:
URL: https://github.com/apache/nifi/pull/4540#discussion_r496792424



##########
File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-resources/src/main/resources/conf/bootstrap.conf
##########
@@ -66,6 +66,15 @@ java.arg.16=-Djavax.security.auth.useSubjectCredsOnly=true
 # Please see https://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_adminserver_config for configuration options.
 java.arg.17=-Dzookeeper.admin.enableServer=false
 
+# The following options configure a Java Agent to handle native library loading.
+# It is needed when a custom jar (eg. JDBC driver) has been configured on a component in the flow and this custom jar depends on a native library
+# and tries to load it by its absolute path (java.lang.System.load(String filename) method call).
+# Use this Java Agent only if you get "Native Library ... already loaded in another classloader" errors otherwise!
+#java.arg.18=-javaagent:./lib/aspectjweaver-${aspectj.version}.jar

Review comment:
       The agent does not require `aspectjweaver.jar` on the classpath so `lib/aspectj` directory could work.
   If there are concerns about having this jar on the system classpath, I can try out that solution too.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] turcsanyip commented on a change in pull request #4540: NIFI-7825: Support native library loading via absolute path

Posted by GitBox <gi...@apache.org>.
turcsanyip commented on a change in pull request #4540:
URL: https://github.com/apache/nifi/pull/4540#discussion_r498244907



##########
File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-resources/src/main/resources/conf/bootstrap.conf
##########
@@ -66,6 +66,15 @@ java.arg.16=-Djavax.security.auth.useSubjectCredsOnly=true
 # Please see https://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_adminserver_config for configuration options.
 java.arg.17=-Dzookeeper.admin.enableServer=false
 
+# The following options configure a Java Agent to handle native library loading.
+# It is needed when a custom jar (eg. JDBC driver) has been configured on a component in the flow and this custom jar depends on a native library
+# and tries to load it by its absolute path (java.lang.System.load(String filename) method call).
+# Use this Java Agent only if you get "Native Library ... already loaded in another classloader" errors otherwise!
+#java.arg.18=-javaagent:./lib/aspectjweaver-${aspectj.version}.jar

Review comment:
       It has been revealed that `aspectjrt` does not needed at runtime, only `aspectjweaver` (which is loaded directly by the agent, not from classpath).
   So I removed `aspectjrt.ajr` from `lib` and moved `aspectjweaver.jar` to `lib/aspectj` subdirectory.
   In this way, there are no AspectJ libraries on the system classpath by default (when the agent is turned off).
   
   When the agent is turned on, it is being loaded by the system classloader (even if `aspectjweaver.jar` is not on the system classpath). So there might be collision between different versions in this case. I believe it is acceptable because only the "agent turned on" case affected. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] bbende commented on a change in pull request #4540: NIFI-7825: Support native library loading via absolute path

Posted by GitBox <gi...@apache.org>.
bbende commented on a change in pull request #4540:
URL: https://github.com/apache/nifi/pull/4540#discussion_r496907835



##########
File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-resources/src/main/resources/conf/bootstrap.conf
##########
@@ -66,6 +66,15 @@ java.arg.16=-Djavax.security.auth.useSubjectCredsOnly=true
 # Please see https://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_adminserver_config for configuration options.
 java.arg.17=-Dzookeeper.admin.enableServer=false
 
+# The following options configure a Java Agent to handle native library loading.
+# It is needed when a custom jar (eg. JDBC driver) has been configured on a component in the flow and this custom jar depends on a native library
+# and tries to load it by its absolute path (java.lang.System.load(String filename) method call).
+# Use this Java Agent only if you get "Native Library ... already loaded in another classloader" errors otherwise!
+#java.arg.18=-javaagent:./lib/aspectjweaver-${aspectj.version}.jar

Review comment:
       Well it does have an effect... If the jars are in lib then they are on the classpath of every NAR, so if someone makes a custom NAR that bundles a different version of aspectj, then there will be two versions on the classpath, and there is nothing the NAR can do to avoid the one in lib.
   
   I would actually vote for option 3... create a new module like `nifi-nar-aspect-utils` or whatever we want to call it, and put the dependency there along with `LoadNativeLibAspect`, then `lib/aspectj` can contain `nifi-nar-aspect-utils` jar and the aspectj jars. Would that work?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] bbende commented on a change in pull request #4540: NIFI-7825: Support native library loading via absolute path

Posted by GitBox <gi...@apache.org>.
bbende commented on a change in pull request #4540:
URL: https://github.com/apache/nifi/pull/4540#discussion_r496726770



##########
File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-resources/src/main/resources/conf/bootstrap.conf
##########
@@ -66,6 +66,15 @@ java.arg.16=-Djavax.security.auth.useSubjectCredsOnly=true
 # Please see https://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_adminserver_config for configuration options.
 java.arg.17=-Dzookeeper.admin.enableServer=false
 
+# The following options configure a Java Agent to handle native library loading.
+# It is needed when a custom jar (eg. JDBC driver) has been configured on a component in the flow and this custom jar depends on a native library
+# and tries to load it by its absolute path (java.lang.System.load(String filename) method call).
+# Use this Java Agent only if you get "Native Library ... already loaded in another classloader" errors otherwise!
+#java.arg.18=-javaagent:./lib/aspectjweaver-${aspectj.version}.jar

Review comment:
       Do we have any concerns about aspectjweaver being directly in the lib directory which puts in on the classpath of every single NAR? Wondering if it should be separated like `lib/aspectj/` which would not be added to NiFi's normal classpath, but I don't know enough to say if it still works correctly then.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] asfgit closed pull request #4540: NIFI-7825: Support native library loading via absolute path

Posted by GitBox <gi...@apache.org>.
asfgit closed pull request #4540:
URL: https://github.com/apache/nifi/pull/4540


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org