Skip to content

Commit 3bb4488

Browse files
author
David Roberts
authored
[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.
1 parent 6caaa7f commit 3bb4488

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/process/AbstractNativeProcess.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,12 @@ public void close() throws IOException {
192192
logTailFuture.get(5, TimeUnit.SECONDS);
193193
}
194194

195-
if (cppLogHandler().seenFatalError()) {
196-
throw ExceptionsHelper.serverError(cppLogHandler().getErrors());
195+
if (cppLogHandler() != null) {
196+
if (cppLogHandler().seenFatalError()) {
197+
throw ExceptionsHelper.serverError(cppLogHandler().getErrors());
198+
}
199+
LOGGER.debug("[{}] {} process exited", jobId, getName());
197200
}
198-
LOGGER.debug("[{}] {} process exited", jobId, getName());
199201
} catch (ExecutionException | TimeoutException e) {
200202
LOGGER.warn(new ParameterizedMessage("[{}] Exception closing the running {} process", jobId, getName()), e);
201203
} catch (InterruptedException e) {
@@ -260,18 +262,20 @@ public ZonedDateTime getProcessStartTime() {
260262
@Override
261263
public boolean isProcessAlive() {
262264
// Sanity check: make sure the process hasn't terminated already
263-
return cppLogHandler().hasLogStreamEnded() == false;
265+
return cppLogHandler() != null && cppLogHandler().hasLogStreamEnded() == false;
264266
}
265267

266268
@Override
267269
public boolean isProcessAliveAfterWaiting() {
268-
cppLogHandler().waitForLogStreamClose(Duration.ofMillis(45));
270+
if (cppLogHandler() != null) {
271+
cppLogHandler().waitForLogStreamClose(Duration.ofMillis(45));
272+
}
269273
return isProcessAlive();
270274
}
271275

272276
@Override
273277
public String readError() {
274-
return cppLogHandler().getErrors();
278+
return (cppLogHandler() == null) ? "" : cppLogHandler().getErrors();
275279
}
276280

277281
protected String jobId() {

0 commit comments

Comments
 (0)