Avoid race when shutting down controller processes (#24579)
This commit terminates any controller processes plugins might have after the node has been closed. This gives the plugins a chance to shut down their controllers gracefully. Previously there was a race condition where controller processes could be shut down gracefully and terminated by two threads running in parallel, leading to non-deterministic outcomes. Additionally, controller processes that failed to shut down gracefully were not forcibly terminated when running as a Windows service; there was a reliance on the plugin to shut down its controller gracefully in this situation. This commit also fixes this problem.
This commit is contained in:
parent
2486086980
commit
d611ab4855
|
@ -163,16 +163,6 @@ final class Bootstrap {
|
|||
|
||||
try {
|
||||
spawner.spawnNativePluginControllers(environment);
|
||||
Runtime.getRuntime().addShutdownHook(new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
spawner.close();
|
||||
} catch (IOException e) {
|
||||
throw new ElasticsearchException("Failed to destroy spawned controllers", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (IOException e) {
|
||||
throw new BootstrapException(e);
|
||||
}
|
||||
|
@ -191,7 +181,7 @@ final class Bootstrap {
|
|||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
IOUtils.close(node);
|
||||
IOUtils.close(node, spawner);
|
||||
LoggerContext context = (LoggerContext) LogManager.getContext(false);
|
||||
Configurator.shutdown(context);
|
||||
} catch (IOException ex) {
|
||||
|
@ -269,7 +259,7 @@ final class Bootstrap {
|
|||
|
||||
static void stop() throws IOException {
|
||||
try {
|
||||
IOUtils.close(INSTANCE.node);
|
||||
IOUtils.close(INSTANCE.node, INSTANCE.spawner);
|
||||
} finally {
|
||||
INSTANCE.keepAliveLatch.countDown();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue