Fix issue with Gradle daemons hanging indefinitely on shutdown (#44867) (#44878)

This commit is contained in:
Mark Vieira 2019-07-25 15:33:51 -07:00 committed by GitHub
parent 03605169f3
commit aebfdf1477
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 25 deletions

View File

@ -19,16 +19,12 @@ public class TestClusterCleanupOnShutdown implements Runnable {
private Set<ElasticsearchCluster> clustersToWatch = new HashSet<>(); private Set<ElasticsearchCluster> clustersToWatch = new HashSet<>();
public void watch(Collection<ElasticsearchCluster> cluster) { public synchronized void watch(Collection<ElasticsearchCluster> clusters) {
synchronized (clustersToWatch) { clustersToWatch.addAll(clusters);
clustersToWatch.addAll(clustersToWatch);
}
} }
public void unWatch(Collection<ElasticsearchCluster> cluster) { public synchronized void unWatch(Collection<ElasticsearchCluster> clusters) {
synchronized (clustersToWatch) { clustersToWatch.removeAll(clusters);
clustersToWatch.removeAll(clustersToWatch);
}
} }
@Override @Override
@ -38,21 +34,23 @@ public class TestClusterCleanupOnShutdown implements Runnable {
Thread.sleep(Long.MAX_VALUE); Thread.sleep(Long.MAX_VALUE);
} }
} catch (InterruptedException interrupted) { } catch (InterruptedException interrupted) {
synchronized (clustersToWatch) { shutdownClusters();
if (clustersToWatch.isEmpty()) { }
return; }
}
logger.info("Cleanup thread was interrupted, shutting down all clusters"); public synchronized void shutdownClusters() {
Iterator<ElasticsearchCluster> iterator = clustersToWatch.iterator(); if (clustersToWatch.isEmpty()) {
while (iterator.hasNext()) { return;
ElasticsearchCluster cluster = iterator.next(); }
iterator.remove(); logger.info("Cleanup thread was interrupted, shutting down all clusters");
try { Iterator<ElasticsearchCluster> iterator = clustersToWatch.iterator();
cluster.stop(false); while (iterator.hasNext()) {
} catch (Exception e) { ElasticsearchCluster cluster = iterator.next();
logger.warn("Could not shut down {}", cluster, e); iterator.remove();
} try {
} cluster.stop(false);
} catch (Exception e) {
logger.warn("Could not shut down {}", cluster, e);
} }
} }
} }

View File

@ -33,7 +33,6 @@ public class TestClustersCleanupExtension {
executorService.submit(cleanupThread); executorService.submit(cleanupThread);
} }
public static void createExtension(Project project) { public static void createExtension(Project project) {
if (project.getRootProject().getExtensions().findByType(TestClustersCleanupExtension.class) != null) { if (project.getRootProject().getExtensions().findByType(TestClustersCleanupExtension.class) != null) {
return; return;
@ -43,7 +42,7 @@ public class TestClustersCleanupExtension {
"__testclusters_rate_limit", "__testclusters_rate_limit",
TestClustersCleanupExtension.class TestClustersCleanupExtension.class
); );
Thread shutdownHook = new Thread(ext.cleanupThread::run); Thread shutdownHook = new Thread(ext.cleanupThread::shutdownClusters);
Runtime.getRuntime().addShutdownHook(shutdownHook); Runtime.getRuntime().addShutdownHook(shutdownHook);
project.getGradle().buildFinished(buildResult -> { project.getGradle().buildFinished(buildResult -> {
ext.executorService.shutdownNow(); ext.executorService.shutdownNow();