commit 1f4b2b49bb6401835ce8ab74be6933d7520043b5 Merge: f091a0d 32afec8 Author: Marco Miller Date: Tue Oct 6 08:28:15 2020 -0400 Merge branch 'stable-3.0' into stable-3.1 * stable-3.0: Bump Bazel version to 3.5.1 Upgrade jackson-core to 2.11.3 Register graceful shutdown for version command Register graceful shutdown for show queue command Register graceful shutdown for show connections command Register graceful shutdown for show caches command Register graceful shutdown for set reviewers command Register graceful shutdown for set project command Register graceful shutdown for set parent command Register graceful shutdown for set members command Register graceful shutdown for set logging level command Register graceful shutdown for set head command Register graceful shutdown for set account command Register graceful shutdown for review command Register graceful shutdown for rename group command Register graceful shutdown for reload config command Register graceful shutdown for query command Register graceful shutdown for list plugins command Register graceful shutdown for plugin admin commands Register graceful shutdown for list user refs command Register graceful shutdown for list projects command Register graceful shutdown for list members command Register graceful shutdown for list logging level command Register graceful shutdown for list groups command Register graceful shutdown for kill command Register graceful shutdown for index start command Register graceful shutdown for index changes in project command Register graceful shutdown for index changes command Register graceful shutdown for index activate command Register graceful shutdown for gc command Register graceful shutdown for flush caches command Register graceful shutdown for create project command Register graceful shutdown for create group command Register graceful shutdown for create branch command Register graceful shutdown for create account command Register graceful shutdown for close connection command Register graceful shutdown for prolog test commands Register graceful shutdown for ban commit command Register graceful shutdown for apropos command Limit graceful shutdown to SSH sessions serving git requests Update git submodules Change-Id: I519ba25b10209f8856ecf289915c65e5eb8ee09a diff --cc java/com/google/gerrit/pgm/Daemon.java index e9beeb5,a5c6dac..238cf29 --- a/java/com/google/gerrit/pgm/Daemon.java +++ b/java/com/google/gerrit/pgm/Daemon.java @@@ -512,10 -526,12 +518,12 @@@ public class Daemon extends SiteProgra } modules.add( new DefaultCommandModule( - slave, + replica, sysInjector.getInstance(DownloadConfig.class), sysInjector.getInstance(LfsPluginAuthCommand.Module.class))); + + modules.addAll(testSshModules); - if (!slave) { + if (!replica) { modules.add(new IndexCommandsModule(sysInjector)); } return sysInjector.createChildInjector(modules); diff --cc java/com/google/gerrit/sshd/AbstractGitCommand.java index 8bf6cd5,90f0c43..9efcff2 --- a/java/com/google/gerrit/sshd/AbstractGitCommand.java +++ b/java/com/google/gerrit/sshd/AbstractGitCommand.java @@@ -48,15 -45,10 +48,16 @@@ public abstract class AbstractGitComman protected Repository repo; protected Project.NameKey projectName; protected Project project; + protected String[] extraParameters; @Override - public void start(Environment env) { + public void start(ChannelSession channel, Environment env) { + enableGracefulStop(); + String gitProtocol = env.getEnv().get(GIT_PROTOCOL); + if (gitProtocol != null) { + extraParameters = gitProtocol.split(":"); + } + Context ctx = context.subContext(newSession(), context.getCommandLine()); final Context old = sshScope.set(ctx); try { diff --cc java/com/google/gerrit/sshd/commands/CloseConnection.java index 093f647,6cd009b..e0b87f8 --- a/java/com/google/gerrit/sshd/commands/CloseConnection.java +++ b/java/com/google/gerrit/sshd/commands/CloseConnection.java @@@ -57,26 -60,37 +57,27 @@@ final class CloseConnection extends Ssh @Override protected void run() throws Failure { + enableGracefulStop(); - IoAcceptor acceptor = sshDaemon.getIoAcceptor(); - if (acceptor == null) { - throw new Failure(1, "fatal: sshd no longer running"); - } - for (String sessionId : sessionIds) { - boolean connectionFound = false; - int id = (int) Long.parseLong(sessionId, 16); - for (IoSession io : acceptor.getManagedSessions().values()) { - AbstractSession serverSession = AbstractSession.getSession(io, true); - SshSession sshSession = - serverSession != null ? serverSession.getAttribute(SshSession.KEY) : null; - if (sshSession != null && sshSession.getSessionId() == id) { - connectionFound = true; - stdout.println("closing connection " + sessionId + "..."); - CloseFuture future = io.close(true); - if (wait) { - try { - future.await(); - stdout.println("closed connection " + sessionId); - } catch (IOException e) { - logger.atWarning().log( - "Wait for connection to close interrupted: %s", e.getMessage()); + SshUtil.forEachSshSession( + sshDaemon, + (k, sshSession, abstractSession, ioSession) -> { + String sessionId = String.format("%08x", sshSession.getSessionId()); + if (sessionIds.remove(sessionId)) { + stdout.println("closing connection " + sessionId + "..."); + CloseFuture future = ioSession.close(true); + if (wait) { + try { + future.await(); + stdout.println("closed connection " + sessionId); + } catch (IOException e) { + logger.atWarning().log( + "Wait for connection to close interrupted: %s", e.getMessage()); + } } } - break; - } - } - if (!connectionFound) { - stderr.print("close connection " + sessionId + ": no such connection\n"); - } + }); + for (String sessionId : sessionIds) { + stderr.print("close connection " + sessionId + ": no such connection\n"); } } } diff --cc java/com/google/gerrit/sshd/commands/LsUserRefs.java index 1a60679,a1af9a0..b8fc55a --- a/java/com/google/gerrit/sshd/commands/LsUserRefs.java +++ b/java/com/google/gerrit/sshd/commands/LsUserRefs.java @@@ -74,9 -74,10 +74,10 @@@ public class LsUserRefs extends SshComm @Override protected void run() throws Failure { + enableGracefulStop(); Account.Id userAccountId; try { - userAccountId = accountResolver.resolve(userName).asUnique().getAccount().getId(); + userAccountId = accountResolver.resolve(userName).asUnique().account().id(); } catch (UnprocessableEntityException e) { stdout.println(e.getMessage()); stdout.flush(); diff --cc java/com/google/gerrit/sshd/commands/PluginLsCommand.java index 3a952f0,7216ed9..504b239 --- a/java/com/google/gerrit/sshd/commands/PluginLsCommand.java +++ b/java/com/google/gerrit/sshd/commands/PluginLsCommand.java @@@ -41,7 -41,8 +41,8 @@@ public class PluginLsCommand extends Ss @Override public void run() throws Exception { + enableGracefulStop(); - Map output = list.apply(TopLevelResource.INSTANCE); + Map output = list.apply(TopLevelResource.INSTANCE).value(); if (format.isJson()) { format diff --cc java/com/google/gerrit/sshd/commands/ShowCaches.java index fdb57ac,039b74e..63a0dda --- a/java/com/google/gerrit/sshd/commands/ShowCaches.java +++ b/java/com/google/gerrit/sshd/commands/ShowCaches.java @@@ -111,7 -110,8 +111,8 @@@ final class ShowCaches extends SshComma } @Override - protected void run() throws UnloggedFailure { + protected void run() throws Failure { + enableGracefulStop(); nw = columns - 50; Date now = new Date(); stdout.format(