Give the Curator 10s to shut down
@@ -4,6 +4,7 @@ package com.yahoo.vespa.curator;
import com.google.inject.Inject;
import com.yahoo.cloud.config.CuratorConfig;
import com.yahoo.component.AbstractComponent;
+import com.yahoo.concurrent.DaemonThreadFactory;
import com.yahoo.path.Path;
import com.yahoo.vespa.curator.api.VespaCurator;
import com.yahoo.vespa.curator.recipes.CuratorCounter;
@@ -35,9 +36,16 @@ import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
+import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
import java.util.function.Function;
+import java.util.logging.Level;
import java.util.logging.Logger;
/**
@@ -313,7 +321,16 @@ public class Curator extends AbstractComponent implements VespaCurator, AutoClos
@Override
public void close() {
- curatorFramework.close();
+ ExecutorService executor = Executors.newSingleThreadExecutor(new DaemonThreadFactory("curator-shutdown"));
+ Future<?> shutdown = CompletableFuture.runAsync(curatorFramework::close, executor);
+ try {
+ shutdown.get(10, TimeUnit.SECONDS);
+ }
+ catch (Exception e) {
+ LOG.log(Level.WARNING, "Failed shutting down curator framework (within 10 seconds)", e);
+ if (e instanceof InterruptedException) Thread.currentThread().interrupt();
+ }
+ executor.shutdownNow();
}
@Override
