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 {
|
try {
|
||||||
spawner.spawnNativePluginControllers(environment);
|
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) {
|
} catch (IOException e) {
|
||||||
throw new BootstrapException(e);
|
throw new BootstrapException(e);
|
||||||
}
|
}
|
||||||
|
@ -191,7 +181,7 @@ final class Bootstrap {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
IOUtils.close(node);
|
IOUtils.close(node, spawner);
|
||||||
LoggerContext context = (LoggerContext) LogManager.getContext(false);
|
LoggerContext context = (LoggerContext) LogManager.getContext(false);
|
||||||
Configurator.shutdown(context);
|
Configurator.shutdown(context);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
|
@ -269,7 +259,7 @@ final class Bootstrap {
|
||||||
|
|
||||||
static void stop() throws IOException {
|
static void stop() throws IOException {
|
||||||
try {
|
try {
|
||||||
IOUtils.close(INSTANCE.node);
|
IOUtils.close(INSTANCE.node, INSTANCE.spawner);
|
||||||
} finally {
|
} finally {
|
||||||
INSTANCE.keepAliveLatch.countDown();
|
INSTANCE.keepAliveLatch.countDown();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue