-
Notifications
You must be signed in to change notification settings - Fork 747
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
close process streams explicitly after the process exits #2053
Conversation
I introduced |
// Close the pipes to avoid file descriptors from being drained | ||
// quickly. Then set the process object to null in the high hopes | ||
// that the garbage collector will finish rest of the cleanup soon. | ||
closeStreams(process); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I am missing something but why are you closing the process here and then you are doing the same in finally
? I think this is basically redundant...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true, moved the close to the finally block. I never liked setting objects to null anyway.
@@ -136,6 +136,21 @@ public int exec(boolean reportExceptions) { | |||
return ret; | |||
} | |||
|
|||
/** | |||
* Close all the 3 streams of a process. | |||
* @param process |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add description to the parameter or delete it. This way it says nothing and just takes one line of code...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
ret = process.exitValue(); | ||
} | ||
} catch (IllegalThreadStateException e) { | ||
if (process != null) { | ||
closeStreams(process); | ||
process.destroy(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
process
will be destroyed twice. Is it supported? JavaDoc does not say...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was an oversight, removed.
try { | ||
if (process != null) { | ||
closeStreams(process); | ||
ret = process.exitValue(); | ||
} | ||
} catch (IllegalThreadStateException e) { | ||
if (process != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it wise to do basically the same thing in the exception handler? Won't be the same exception thrown once again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed.
*/ | ||
private static void closeStreams(Process process) { | ||
try { | ||
process.getOutputStream().close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Java 8 Netbeans complain if the try/catch block for the IOException is not there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I mean what is the purpose of closing the streams right before the destroy()
call which under the hood does exactly the same. Does destroy()
throw an exception which prevents closing the streams?
lgtm, after you sort out comments from Adam, feel free to merge ... sanity checking wise it's OK |
Hi, @vladak. Please see the old OpenGrok |
@idodeclare thanks, redone. Got rid of the method as a result. |
I looked into the process implementation because I was quite curious how it is done. I believe it would be safer to call Rationale for using
@vladak you know OS stuff much much better than I do so if you think it's okay then I have no problem with it :) |
I don't quite like the As for the Solaris (and AIX where the constrains are actually worse according to the comments in the |
With this change the history part of the indexing works again, hurrah!
Also, I renamed the single letter
Timer
instance and reordered the check so it happens early in the finally block.