[ML] Add null checks for C++ log handler (#62238)

It has been observed that if the normalizer process fails
to connect to the JVM then this causes a null pointer
exception as the JVM tries to close the native process
object.  The accessors and close methods of the native
process class that access the C++ log handler should not
assume that it connected correctly.
This commit is contained in:
David Roberts 2020-09-14 09:18:49 +01:00
parent c88f4174ec
commit d8288526d9
1 changed files with 10 additions and 6 deletions

View File

@ -197,10 +197,12 @@ public abstract class AbstractNativeProcess implements NativeProcess {
logTailFuture.get(5, TimeUnit.SECONDS);
}
if (cppLogHandler().seenFatalError()) {
throw ExceptionsHelper.serverError(cppLogHandler().getErrors());
if (cppLogHandler() != null) {
if (cppLogHandler().seenFatalError()) {
throw ExceptionsHelper.serverError(cppLogHandler().getErrors());
}
LOGGER.debug("[{}] {} process exited", jobId, getName());
}
LOGGER.debug("[{}] {} process exited", jobId, getName());
} catch (ExecutionException | TimeoutException e) {
LOGGER.warn(new ParameterizedMessage("[{}] Exception closing the running {} process", jobId, getName()), e);
} catch (InterruptedException e) {
@ -268,18 +270,20 @@ public abstract class AbstractNativeProcess implements NativeProcess {
@Override
public boolean isProcessAlive() {
// Sanity check: make sure the process hasn't terminated already
return cppLogHandler().hasLogStreamEnded() == false;
return cppLogHandler() != null && cppLogHandler().hasLogStreamEnded() == false;
}
@Override
public boolean isProcessAliveAfterWaiting() {
cppLogHandler().waitForLogStreamClose(Duration.ofMillis(45));
if (cppLogHandler() != null) {
cppLogHandler().waitForLogStreamClose(Duration.ofMillis(45));
}
return isProcessAlive();
}
@Override
public String readError() {
return cppLogHandler().getErrors();
return (cppLogHandler() == null) ? "" : cppLogHandler().getErrors();
}
protected String jobId() {