From a206e11fad0a0dca1ae4414e898cec0e047b84d3 Mon Sep 17 00:00:00 2001 From: Shawn Pearce Date: Mon, 29 Jul 2013 22:29:54 -0700 Subject: [PATCH] Stop SshCommandDestroy thread pool on server shutdown This avoids leaking the thread during acceptance tests. Change-Id: I18a7f57bc6b381f28006a20b6cffda0be6b3fb46 --- .../gerrit/sshd/CommandFactoryProvider.java | 19 ++++++++++++++++--- .../com/google/gerrit/sshd/SshModule.java | 1 + 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/CommandFactoryProvider.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/CommandFactoryProvider.java index 910f5f34e0..a2e65424bd 100644 --- a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/CommandFactoryProvider.java +++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/CommandFactoryProvider.java @@ -16,6 +16,7 @@ package com.google.gerrit.sshd; import com.google.common.util.concurrent.Atomics; import com.google.common.util.concurrent.ThreadFactoryBuilder; +import com.google.gerrit.extensions.events.LifecycleListener; import com.google.gerrit.reviewdb.server.ReviewDb; import com.google.gerrit.server.config.GerritServerConfig; import com.google.gerrit.server.git.WorkQueue; @@ -23,6 +24,7 @@ import com.google.gerrit.sshd.SshScope.Context; import com.google.gwtorm.server.SchemaFactory; import com.google.inject.Inject; import com.google.inject.Provider; +import com.google.inject.Singleton; import org.apache.sshd.server.Command; import org.apache.sshd.server.CommandFactory; @@ -39,7 +41,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.Executor; +import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.ScheduledExecutorService; @@ -49,7 +51,9 @@ import java.util.concurrent.atomic.AtomicReference; /** * Creates a CommandFactory using commands registered by {@link CommandModule}. */ -class CommandFactoryProvider implements Provider { +@Singleton +class CommandFactoryProvider implements Provider, + LifecycleListener { private static final Logger logger = LoggerFactory .getLogger(CommandFactoryProvider.class); @@ -57,7 +61,7 @@ class CommandFactoryProvider implements Provider { private final SshLog log; private final SshScope sshScope; private final ScheduledExecutorService startExecutor; - private final Executor destroyExecutor; + private final ExecutorService destroyExecutor; private final SchemaFactory schemaFactory; @Inject @@ -79,6 +83,15 @@ class CommandFactoryProvider implements Provider { .build()); } + @Override + public void start() { + } + + @Override + public void stop() { + destroyExecutor.shutdownNow(); + } + @Override public CommandFactory get() { return new CommandFactory() { diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/SshModule.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/SshModule.java index 2e42c23e7a..0115065c94 100644 --- a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/SshModule.java +++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/SshModule.java @@ -107,6 +107,7 @@ public class SshModule extends FactoryModule { listener().toInstance(registerInParentInjectors()); listener().to(SshLog.class); listener().to(SshDaemon.class); + listener().to(CommandFactoryProvider.class); } }); }