Name the log tail thread and mark it as a daemon
This commit provides an explicit name for the log tail thread, otherwise the thread shows up with a generic name like Thread-12 in stack dumps. While the stack trace provides enough information to conclude what this thread is doing, it is better to be more explicit about the purpose of this thread so that that can be discerned directly from the name of the thread. Additionally, we mark this thread as a daemon thread. Since this thread is created by the main thread during node initialization it defaults to being a user thread. Since the JVM only exits when the only threads running are not user threads, if this thread were to somehow block then it could prevent the server JVM from exiting. As such, this thread should be marked as a daemon thread. Relates elastic/x-pack-elasticsearch#1969 Original commit: elastic/x-pack-elasticsearch@b3761c7d91
This commit is contained in:
parent
c22f618a1a
commit
5ed683538d
|
@ -50,7 +50,6 @@ public class NativeController {
|
||||||
|
|
||||||
private final CppLogMessageHandler cppLogHandler;
|
private final CppLogMessageHandler cppLogHandler;
|
||||||
private final OutputStream commandStream;
|
private final OutputStream commandStream;
|
||||||
private Thread logTailThread;
|
|
||||||
|
|
||||||
NativeController(Environment env, NamedPipeHelper namedPipeHelper) throws IOException {
|
NativeController(Environment env, NamedPipeHelper namedPipeHelper) throws IOException {
|
||||||
ProcessPipes processPipes = new ProcessPipes(env, namedPipeHelper, ProcessCtrl.CONTROLLER, null,
|
ProcessPipes processPipes = new ProcessPipes(env, namedPipeHelper, ProcessCtrl.CONTROLLER, null,
|
||||||
|
@ -61,15 +60,22 @@ public class NativeController {
|
||||||
}
|
}
|
||||||
|
|
||||||
void tailLogsInThread() {
|
void tailLogsInThread() {
|
||||||
logTailThread = new Thread(() -> {
|
final Thread logTailThread = new Thread(
|
||||||
try {
|
() -> {
|
||||||
cppLogHandler.tailStream();
|
try {
|
||||||
cppLogHandler.close();
|
cppLogHandler.tailStream();
|
||||||
} catch (IOException e) {
|
cppLogHandler.close();
|
||||||
LOGGER.error("Error tailing C++ controller logs", e);
|
} catch (IOException e) {
|
||||||
}
|
LOGGER.error("Error tailing C++ controller logs", e);
|
||||||
LOGGER.info("Native controller process has stopped - no new native processes can be started");
|
}
|
||||||
});
|
LOGGER.info("Native controller process has stopped - no new native processes can be started");
|
||||||
|
},
|
||||||
|
"ml-cpp-log-tail-thread");
|
||||||
|
/*
|
||||||
|
* This thread is created on the main thread so would default to being a user thread which could prevent the JVM from exiting if
|
||||||
|
* this thread were to still be running during shutdown. As such, we mark it as a daemon thread.
|
||||||
|
*/
|
||||||
|
logTailThread.setDaemon(true);
|
||||||
logTailThread.start();
|
logTailThread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue