Reputation: 11
I've been using roughly the same utility code to handle executing an external Process for at least a decade. Recently a customer hit a case where the following ~code was interrupted:
try {
int exitCode = myProcess.waitFor();
// do things with this code
} catch (InterruptedException ie) {
// log stuff here including thread name, but otherwise swallow the exception
}
We have no code that would interrupt the above, except during shutdown when it doesn't matter that it happened. That wasn't the case here: the user saw the external process interrupted, which meant we didn't have a proper exit code, and something went wrong because of it. Maybe importantly, the thread that was interrupted was "main."
I can only see two possibilities here. Either:
We've never seen this happen before (in over ten years with many many users), and I can't find a problem in the code leading up to the above, but it's simple enough for #1 to put in a Thread.interrupted()
call to check on it and at least work around the problem.
My question is if anything external could cause #2? I've tried testing by executing an external script that just waits 30 seconds, and I try various ways of killing the processes that were created. But in each of my dumb tests the java Process finishes with a proper exit code. I can't do anything external to cause that waitFor call to be interrupted.
So, anyone know of a way to externally interrupt the process? It'd be good form, of course, to handle it properly throughout the code, but it would be a large change to handle something that might never happen and, worse, is untestable. The simple Thread.interrupted call should not hurt anything and would let us know there's a bug somewhere if we see it; I'm much more comfortable with it.
Note: googling for this has not been helpful since every keyword points to info on handling the interruption, not causing it. Thus my potentially dumb post.
Upvotes: 1
Views: 43