Hello Team,
We are getting following Exception from jodconverter-core-3.0-SNAPSHOT-patched.jar.
The Jar is referenced from Alfresco, Alfresco starts four processes on Linux. At some point of time we get following exception on one of the port and the openoffice process does not work anymore. Hence we need to manually kill all Openoffice processes and restart the server.
Sep 9, 2014 4:53:51 AM org.artofsolving.jodconverter.office.OfficeProcess forciblyTerminate
INFO: trying to forcibly terminate process: 'socket,host=127.0.0.1,port=22021,tcpNoDelay=1' (pid -2)
Exception in thread "OfficeProcessThread-0" org.artofsolving.jodconverter.office.OfficeException: could not terminate process
at org.artofsolving.jodconverter.office.ManagedOfficeProcess.doTerminateProcess(ManagedOfficeProcess.java:178)
at org.artofsolving.jodconverter.office.ManagedOfficeProcess.access$2(ManagedOfficeProcess.java:173)
at org.artofsolving.jodconverter.office.ManagedOfficeProcess$4.run(ManagedOfficeProcess.java:102)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.IllegalArgumentException: invalid pid: -2
at org.artofsolving.jodconverter.process.LinuxProcessManager.kill(LinuxProcessManager.java:68)
at org.artofsolving.jodconverter.office.OfficeProcess.forciblyTerminate(OfficeProcess.java:278)
at org.artofsolving.jodconverter.office.ManagedOfficeProcess.doTerminateProcess(ManagedOfficeProcess.java:175)
... 5 more
We have debugged the issue and following were our findings related to this issue.
1. OfficeProcess.java has start() method, which is having two statements.
Statement-1: process = processBuilder.start();
Statement-2: pid = processManager.findPid(processQuery); //calls org.artofsolving.jodconverter.process.LinuxProcessManager.findPid(ProcessQuery processQuery) method.
2. Statement-1 is calls following linux command.
- /opt/alfresco-4.1.4/openoffice/program/soffice.bin "-accept=socket,host=127.0.0.1,port=22021;urp; -env:UserInstallation=file:///opt/alfresco-4.1.4/tomcat/temp/.jodconverter_socket_host-127.0.0.1_port-22021" -headless -nocrashreport -nodefault -nofirststartwizard -nolockcheck -nologo -norestore
3. Statement-2 executes following linux command.
4. Actual Cause Of The Issue:
- Some times when process starts using OfficeProcess.start() method, which executes Statement-2, the statement gets process-id of that process, but somehow the process is still loading into background.
- Hence "ps -e -ww -o pid,args" command could not load the process with process-id. Hence pid will be set to -2.
- Now when the same process is been killed by method OfficeProcess.forciblyTerminate, It throws the above exception.
- Since method OfficeProcess.forciblyTerminate uses process id to kill the process in linux, and It was not set on the startup of the process. Hence not able to kill process.
Resolution:
We have put following step#3 in the method OfficeProcess.start() to fix the code.
1. Start the process.
2. Get the process id and set it to variable pid.
3. If process id is not found then sleep the thread for 50 miliseconds and check it again. reiterate this step until processid is not found.
I have attached actual source code file "OfficeProcess.java" and modified souce code "OfficeProcess.java_Modified". Please check start() process for more information.
This fixes the issue "Caused by: java.lang.IllegalArgumentException: invalid pid: -2".
Anyone has experienced this issue and have any fix related to it.?
Would like to know, is there already a fix for this issue in other versions?
Thanks in advance for the help.
Thanks,
Ravi Chandanani
Consultant - Alfresco