Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary warnings in the native build after netty version update #3861

Closed
TharmiganK opened this issue Dec 19, 2022 · 6 comments · Fixed by ballerina-platform/module-ballerina-http#1396
Assignees
Labels
Milestone

Comments

@TharmiganK
Copy link
Contributor

TharmiganK commented Dec 19, 2022

Description:

Due to the recent update of the netty version in the http module, the following warnings are printed when executing the bal build --native command.

  1. Warnings from the GraalVM:
Warning: Could not register io.netty.handler.proxy.Socks5ProxyHandler: queryAllPublicMethods for reflection. Reason: java.lang.NoClassDefFoundError: io/netty/handler/codec/socksx/v5/Socks5InitialRequest.
Warning: Could not register io.netty.handler.codec.compression.Lz4FrameDecoder: queryAllPublicMethods for reflection. Reason: java.lang.NoClassDefFoundError: net/jpountz/lz4/LZ4Exception.
Warning: Could not register io.netty.handler.codec.compression.Lz4FrameEncoder: queryAllPublicMethods for reflection. Reason: java.lang.NoClassDefFoundError: net/jpountz/lz4/LZ4Exception.
Warning: Could not register io.netty.handler.codec.marshalling.CompatibleMarshallingDecoder: queryAllPublicMethods for reflection. Reason: java.lang.NoClassDefFoundError: org/jboss/marshalling/ByteInput.
Warning: Could not register io.netty.handler.codec.marshalling.CompatibleMarshallingEncoder: queryAllPublicMethods for reflection. Reason: java.lang.NoClassDefFoundError: org/jboss/marshalling/ByteOutput.
Warning: Could not register io.netty.handler.codec.marshalling.MarshallingDecoder: queryAllPublicMethods for reflection. Reason: java.lang.NoClassDefFoundError: org/jboss/marshalling/ByteInput.
Warning: Could not register io.netty.handler.codec.marshalling.MarshallingEncoder: queryAllPublicMethods for reflection. Reason: java.lang.NoClassDefFoundError: org/jboss/marshalling/ByteOutput.
Warning: Could not register io.netty.handler.codec.protobuf.ProtobufDecoder: queryAllPublicMethods for reflection. Reason: java.lang.NoClassDefFoundError: com/google/protobuf/ExtensionRegistryLite.
Warning: Could not register io.netty.handler.codec.compression.Lz4FrameDecoder: queryAllPublicMethods for reflection. Reason: java.lang.NoClassDefFoundError: net/jpountz/lz4/LZ4Exception.
Warning: Could not register io.netty.handler.codec.compression.Lz4FrameEncoder: queryAllPublicMethods for reflection. Reason: java.lang.NoClassDefFoundError: net/jpountz/lz4/LZ4Exception.
Warning: Could not register io.netty.handler.codec.marshalling.CompatibleMarshallingDecoder: queryAllPublicMethods for reflection. Reason: java.lang.NoClassDefFoundError: org/jboss/marshalling/ByteInput.
Warning: Could not register io.netty.handler.codec.marshalling.CompatibleMarshallingEncoder: queryAllPublicMethods for reflection. Reason: java.lang.NoClassDefFoundError: org/jboss/marshalling/ByteOutput.
Warning: Could not register io.netty.handler.codec.marshalling.MarshallingDecoder: queryAllPublicMethods for reflection. Reason: java.lang.NoClassDefFoundError: org/jboss/marshalling/ByteInput.
Warning: Could not register io.netty.handler.codec.marshalling.MarshallingEncoder: queryAllPublicMethods for reflection. Reason: java.lang.NoClassDefFoundError: org/jboss/marshalling/ByteOutput.
Warning: Could not register io.netty.handler.codec.protobuf.ProtobufDecoder: queryAllPublicMethods for reflection. Reason: java.lang.NoClassDefFoundError: com/google/protobuf/ExtensionRegistryLite.
  1. Warning from netty during the Performance analysis step :
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by io.netty.util.internal.ReflectionUtil (file:/Users/user/Documents/GraalVM/ballerina-bbes/http-bbes/01-REST-API/01-service-path-and-resource-path/target/bin/service_path_and_resource_path.jar) to constructor java.nio.DirectByteBuffer(long,int)
WARNING: Please consider reporting this to the maintainers of io.netty.util.internal.ReflectionUtil
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

The first one is printed because of the native image reflection configs which are added to the above netty version. The same issue was there in Quarkus. And as a solution they have excluded those reflection configs during the build.

The second one is related to some netty level logs.

Describe your task(s)

  • Need to add a similar fix like Quarkus for fist set of warnings since they are unnecessary.
  • Need to check if there is a way to disable the netty logs during the analysis
@TharmiganK TharmiganK self-assigned this Dec 19, 2022
@TharmiganK TharmiganK added module/http Team/PCM Protocol connector packages related issues Area/GraalVM labels Dec 19, 2022
@TharmiganK TharmiganK moved this to In Progress in Ballerina Team Main Board Dec 19, 2022
@TharmiganK
Copy link
Contributor Author

TharmiganK commented Dec 19, 2022

OPTION 1 to resolve GraalVM warnings: (I think this should be the ideal solution)

The GraalVM warnings are resolved by removing those reflection configs. The following directives should be passed along with the native-image build command :

--exclude-config target/bin/*.jar /META-INF/native-image/io.netty/netty-handler/generated/handlers/reflect-config.json 
--exclude-config target/bin/*.jar /META-INF/native-image/io.netty/netty-handler-proxy/generated/handlers/reflect-config.json
--exclude-config target/bin/*.jar /META-INF/native-image/io.netty/netty-codec/generated/handlers/reflect-config.json

With the latest version of GraalVM, adding these from the module level native-properties.json is not possible. So these should be added from bal build --native build tool.

@TharmiganK
Copy link
Contributor Author

TharmiganK commented Dec 20, 2022

OPTION 2 to resolve GraalVM warnings:

Another workaround is adding the following dependencies(which are unnecessary) in http module. This resolved the GraalVM warnings :

io.netty:netty-codec-socks:4.1.86-Final
net.jpountz.lz4:lz4:1.3.0
org.jboss.marshalling:jboss-marshalling:2.0.5.Final
com.google.protobuf:protobuf-java:2.6.1

@chamil321
Copy link
Contributor

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by io.netty.util.internal.ReflectionUtil (file:/Users/user/Documents/GraalVM/ballerina-bbes/http-bbes/01-REST-API/01-service-path-and-resource-path/target/bin/service_path_and_resource_path.jar) to constructor java.nio.DirectByteBuffer(long,int)
WARNING: Please consider reporting this to the maintainers of io.netty.util.internal.ReflectionUtil
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

The ideal and the easy solution would be update the build tool with configs to remove those reflection configs. Otherwise adding unnecessary dependencies to fix this problem is complex as it should be done to all Netty dependent modules and still there will be warning as mentioned above.

@TharmiganK
Copy link
Contributor Author

TharmiganK commented Dec 20, 2022

The netty-level warning is printed due to this system property which is added as default in the native-image build : io.netty.tryReflectionSetAccessible=true. This is recently added to netty. Before this change the default value was false for java 11.

To resolve the netty-level warning at Performing analysis step of the native build, we may use a GraalVM Feature class like this, which is used in quarks to change log level during the native build.

I'll check the feasibility of adding this to http-native

@TharmiganK
Copy link
Contributor Author

TharmiganK commented Dec 21, 2022

I have tried to add a GraalVM Feature class in http to resolve the following log:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by io.netty.util.internal.ReflectionUtil (file:/Users/user/Documents/GraalVM/ballerina-bbes/http-bbes/01-REST-API/01-service-path-and-resource-path/target/bin/service_path_and_resource_path.jar) to constructor java.nio.DirectByteBuffer(long,int)
WARNING: Please consider reporting this to the maintainers of io.netty.util.internal.ReflectionUtil
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

But I couldn't find the logger which prints this warnings yet.

Btw there is another option where we pass the following property when building the native image:

io.netty.tryReflectionSetAccessible=false

Actually this is the default behavior when we run bal build \ bal run. But as per this discussion, it is claimed that setting this property to true prevents memory leaks when running it as native-image.

@TharmiganK
Copy link
Contributor Author

In the above PRs, only the GraalVM warnings are fixed by adding the required dependencies. The netty warning regarding the illegal reflection access can be resolved by a similar approach used in this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants