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

Unable to install the patch in MacOs #13

Closed
pavan2004it opened this issue Dec 15, 2021 · 14 comments
Closed

Unable to install the patch in MacOs #13

pavan2004it opened this issue Dec 15, 2021 · 14 comments

Comments

@pavan2004it
Copy link

Environment:

macOs Monterey 12.1
java -version
openjdk version "11.0.9.1" 2020-11-04 LTS
OpenJDK Runtime Environment Corretto-11.0.9.12.1 (build 11.0.9.1+12-LTS)
OpenJDK 64-Bit Server VM Corretto-11.0.9.12.1 (build 11.0.9.1+12-LTS, mixed mode)

I tried to run the below command :
jar -cfm Log4jHotPatch.jar Manifest.mf *.class

Got the error below:

java.io.FileNotFoundException: Manifest.mf (No such file or directory)
at java.base/java.io.FileInputStream.open0(Native Method)
at java.base/java.io.FileInputStream.open(FileInputStream.java:219)
at java.base/java.io.FileInputStream.(FileInputStream.java:157)
at java.base/java.io.FileInputStream.(FileInputStream.java:112)
at jdk.jartool/sun.tools.jar.Main.run(Main.java:267)
at jdk.jartool/sun.tools.jar.Main.main(Main.java:1681)

Am i missing something.

@caojoshua
Copy link

Did you accidentally delete Manifest.mf? It is located at the root of the repo https://github.com/corretto/hotpatch-for-apache-log4j2/blob/main/Manifest.mf. Make sure you are running the jar command from the root of the repo.

The commands work for me on macos 11, and they should be the same for your version.

@pavan2004it
Copy link
Author

Did you accidentally delete Manifest.mf? It is located at the root of the repo https://github.com/corretto/hotpatch-for-apache-log4j2/blob/main/Manifest.mf. Make sure you are running the jar command from the root of the repo.

The commands work for me on macos 11, and they should be the same for your version.

You are right looks like i accidently deleted the file , i just cloned the repo again and ran the command the command worked

@pavan2004it
Copy link
Author

pavan2004it commented Dec 15, 2021

I am getting a different error though when i run the command sudo java Log4jHotPatch :

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: Log4jHotPatch has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:473)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:601)

@caojoshua
Copy link

Make sure you use the same version of java, javac, and jar. I would delete all the *.class files, and run the commands again using only binaries within the same $JAVA_HOME ie. /Library/Java/JavaVirtualMachines/<jdk version>/bin (could be different on your machine).

@caojoshua
Copy link

Correction: it seems you built the patch with java 11 (classfile version 55), and are applying the changes to a running Java 8 process (classfile version 52). You can try running all the steps in the README, following the directions for Java 8.

Thanks @alvdavi for notifying me of this.

@pavan2004it
Copy link
Author

Make sure you use the same version of java, javac, and jar. I would delete all the *.class files, and run the commands again using only binaries within the same $JAVA_HOME ie. /Library/Java/JavaVirtualMachines/<jdk version>/bin (could be different on your machine).

I was able to fix the issue but ran into a different one in jenkins, i am running a jenkins instance and when i try executing against the process i am getting the below error also i have mentioned the process info below.

Is this expected ..?

com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file /var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/T/.java_pid66686: target process 66686 doesn't respond within 10500ms or HotSpot VM not loaded
at jdk.attach/sun.tools.attach.VirtualMachineImpl.(VirtualMachineImpl.java:96)
at jdk.attach/sun.tools.attach.AttachProviderImpl.attachVirtualMachine(AttachProviderImpl.java:58)
at jdk.attach/com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:207)
at Log4jHotPatch.loadInstrumentationAgent(Log4jHotPatch.java:222)
at Log4jHotPatch.main(Log4jHotPatch.java:313)
Error: couldn't loaded the agent into JVM process 66686
Are you running as a different user (including root) than process 66686?
Errors occurred deploying hot patch. If you are using java 8 to run this
tool against JVM 11 or later, the target JVM may still be patched. Please look for a message
like 'Loading Java Agent (using ASM 6).' in stdout of the target JVM. Also note that JVM 17+
are not supported.

Process Info

pavankumar 66686 0.0 1.4 56299296 953424 ?? S 10:40AM 0:28.25 /usr/local/opt/openjdk@11/bin/java -Dmail.smtp.starttls.enable=true -jar /usr/local/opt/jenkins-lts/libexec/jenkins.war --httpListenAddress=127.0.0.1 --httpPort=8080

@caojoshua
Copy link

Can you try running as root? Looks like the same issue in the README Known Issues

@pavan2004it
Copy link
Author

pavan2004it commented Dec 15, 2021

Can you try running as root? Looks like the same issue in [the README Known Issues](https://github.com/corretto/hotpatch-for-apache-log4j2#known-issues

Trying now

@pavan2004it
Copy link
Author

Same error.

Also the documentation looks to be updated , do you want me to try the new instructions..?

@caojoshua
Copy link

You can try the new instructions, but I don't suspect it will make a difference. You can make sure your jenkins is running on jdk11, and is the same version that you built the patch with. Also, try running the patch with the same user that is running jenkins.

We have not done any testing on mac, I'll see if I can reproduce this issue.

@caojoshua
Copy link

I can successfully run the patch on my Mac machine. Still not sure what is the problem on your side.

Can you share the exact command you are running? And make sure you provide the correct PID?

Can you also create a simple java process that just calls Thread.sleep(), and try running the patch against that?

@pavan2004it
Copy link
Author

sure i will give it a try and let you know

@pavan2004it
Copy link
Author

Its working now with the gradle build.

@pavan2004it
Copy link
Author

Thanks for the help @caojoshua

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

No branches or pull requests

2 participants