Rethrow SSHException warnings without stacktrace to reduce log spam

XMLWordPrintable

      Problem Definition

      Continuous SSHExceptions (which are very common on a CI server where credentials go stale and plans become legacy) while polling produce large stack traces that can double log sizes on busy instances. Example:

      2019-03-29 11:46:29,330 WARN [Connection killer] [SshProxyCommand] SSH proxy tried to connect to [git@server/10.0.0.1:7999]: and failed due to the following error: [Authenticating remote session failed]
      org.apache.sshd.common.SshException: No more authentication methods available
          at org.apache.sshd.client.session.ClientUserAuthService.tryNext(ClientUserAuthService.java:315)
          at org.apache.sshd.client.session.ClientUserAuthService.processUserAuth(ClientUserAuthService.java:252)
          at org.apache.sshd.client.session.ClientUserAuthService.process(ClientUserAuthService.java:199)
          at org.apache.sshd.common.session.helpers.AbstractSession.doHandleMessage(AbstractSession.java:530)
          at org.apache.sshd.common.session.helpers.AbstractSession.handleMessage(AbstractSession.java:463)
          at org.apache.sshd.common.session.helpers.AbstractSession.decode(AbstractSession.java:1325)
          at org.apache.sshd.common.session.helpers.AbstractSession.messageReceived(AbstractSession.java:424)
          at org.apache.sshd.common.session.helpers.AbstractSessionIoHandler.messageReceived(AbstractSessionIoHandler.java:67)
          at org.apache.sshd.common.io.nio2.Nio2Session.handleReadCycleCompletion(Nio2Session.java:285)
          at org.apache.sshd.common.io.nio2.Nio2Session$2.onCompleted(Nio2Session.java:265)
          at org.apache.sshd.common.io.nio2.Nio2Session$2.onCompleted(Nio2Session.java:262)
          at org.apache.sshd.common.io.nio2.Nio2CompletionHandler$1.run(Nio2CompletionHandler.java:37)
          at java.security.AccessController.doPrivileged(Native Method)
          at org.apache.sshd.common.io.nio2.Nio2CompletionHandler.completed(Nio2CompletionHandler.java:34)
          at sun.nio.ch.Invoker.invokeUnchecked(Invoker.java:126)
          at sun.nio.ch.Invoker$2.run(Invoker.java:218)
          at sun.nio.ch.AsynchronousChannelGroupImpl$1.run(AsynchronousChannelGroupImpl.java:112)
          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
          at java.lang.Thread.run(Thread.java:745)
      

      Suggested Solution

      Rethrow org.apache.sshd.common.SshException (not org.apache.sshd.common.RuntimeSshException as the caused by is often helpful, e.g. no route to host / connection refused) without the Stack included. Preserve the exception message:

      org.apache.sshd.common.SshException: No more authentication methods available
      

      Print the stack only at DEBUG log level.

            Assignee:
            Unassigned
            Reporter:
            Jeremy Owen
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: