7

I am invoking some EXE's(7za.exe, pg_basebackup.exe, ...) from JAVA ProcessBuilder. It is working without any issues for 2 or 3 days (EXE will be called daily). After that EXE's are crashing continuously.

7za.exe error:
Exit code :: -1.073.741.502

Windows Event log error:
Faulting application name: 7za.exe, version: 9.20.0.0, time stamp: 0x4ce553f5 Faulting module name: KERNELBASE.dll, version: 6.2.9200.21941, time stamp: 0x5792e533
Exception code: 0xc0000142
Fault offset: 0x000683ba
Faulting process id: 0x10bc
Faulting application start time: 0x01d2cebdff3bb05a
Faulting application path: EXEpath\bin\7za.exe
Faulting module path: KERNELBASE.dll
Report Id: 3d27046a-3ab1-11e7-93fe-00505680156e
Faulting package full name:
Faulting package-relative application ID:

Code snippet

File workingDir = new File(workingDirectory);
ProcessBuilder pb = new ProcessBuilder(argumentsList);
pb.redirectErrorStream(true);
pb.directory(workingDir);        
Process process = pb.start();
BufferedReader commandOutput = new BufferedReader(new 
InputStreamReader(process.getInputStream()));
String s = null;
while ((s = commandOutput.readLine()) != null) {
    print(s);
}
int exitCode = process.exitValue();

Also it is not happening in all the machines which run this code. Is it any memory leakage OR OS level error? Please advise.

Thanks in advance.

Edit 1: Same kind of error in c#. It also contains fix.
https://social.msdn.microsoft.com/Forums/vstudio/en-US/cb9a15ed-4401-47f1-8c78-0c63c3da677d/process-returns-0xc0000142-when-started-from-a-windows-service-prividing-the-credentials?forum=clr
How to achieve it in java?

Edit 2: Java is running as a service (using wrapper)
Java version : 1.0.051
Windows version : Windows server 2012 and R2(64bit), Windows 7(64bit), Windows 8(64bit)

Aravindharaj G
  • 407
  • 5
  • 16
  • It looks like your path is a bit mangled: `EXEpath\bin\7za.exe` ? maybe you accidentally typed something in a place you shouldn't have :-) – Ivonet Dec 11 '17 at 13:33
  • Please ignore that location. That is not the actual location. – Aravindharaj G Dec 13 '17 at 11:37
  • Does the exes work if you start them manually ? (by double clicking on them) – Asoub Jan 09 '18 at 13:29
  • yes. Even I have tried with invoking another JVM. It works. It will reproduce only after 2/3 days running in the same JVM. – Aravindharaj G Jan 09 '18 at 14:22
  • 4
    How does your *Java* program run? As a service? This is kind of important info. so are *Win* version, *Java* version. Can you reproduce it manually? What do you mean that with another *jvm* it works? does the java process live through those 2 - 3 days? did you monitor its memory, threads, and other characteristics (from *TaskMgr*)? – CristiFati Jan 10 '18 at 09:41
  • 1
    Do you call a lot of these processes? It appears from https://github.com/moliva/proactive/blob/master/src/Extensions/org/objectweb/proactive/extensions/processbuilder/WindowsProcess.java#L103 that you're "running out of non interactive desktop heap" do you see the 7za processes exiting after you call them, in task manager? thought for work around: call a batch file that calls 7za.exe, possibly call #inheritIO GL! – rogerdpack Jan 15 '18 at 16:58
  • Please show your Java code. Do you call `process.close()` when done? – kichik Jan 15 '18 at 21:13
  • This problem is occurring in few machines only and also it is reproducing in those machines. Tried to run the application in cmd (invoking another JVM) and it is working, At the same time it is failing in JVM which runs as a service. Java heap is not filling and there is no out of memory error. – Aravindharaj G Jan 18 '18 at 11:40
  • I am not calling `process.close()`. This method is not available in process object returned by `ProcessBuilder` class. – Aravindharaj G Jan 22 '18 at 06:14

1 Answers1

0

So I agree with the comments above asking for additional detail to identify the underlying cause of this issue (number of processes when the issues occurs, metrics of the instance, etc). Generally speaking I would argue that it is an anti-pattern to call an executable from java if you can avoid it. In this case I would recommend you try to replace the call to the executable with something like the 7-zip binding.

This should provide you better insight into how the underlying processes are performing and would move ownership and management of the processes under the JVM.

Tristan
  • 279
  • 5
  • 21