diff options
author | Mark Bekhet <mark.bekhet@ericsson.com> | 2019-06-13 14:08:36 -0400 |
---|---|---|
committer | Mark Bekhet <mark.bekhet@ericsson.com> | 2020-12-07 08:23:42 -0500 |
commit | 5e4a4e7e4855bf1aa1166db55bf0d43c3a8f10a1 (patch) | |
tree | 2be146451adae85e7acc06710bff3d8cbaca6c6f | |
parent | 9134e7917ea772732726f9469a3a64e0cf4050ba (diff) |
Avoid logging "length=0" exception
Avoid logging ssh exception for "stream is already closed" when length=0
if present in the stacktrace. This will reduce noise and we will be able
to see if we get this exception when length is not 0.
This exception is related to ssh streams being prematurely closed by the
connected slave frontends. This exception can be safely omitted from the
logs because it is thrown when sshd.flush is called and the channel is
closed. Length = 0 means that there was nothing to be flushed and no new
information is provided by this stack trace.
Change-Id: I85f77cab03453ec51d33b226804ed7f2a454ae6f
-rw-r--r-- | java/com/google/gerrit/sshd/BaseCommand.java | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/java/com/google/gerrit/sshd/BaseCommand.java b/java/com/google/gerrit/sshd/BaseCommand.java index a027dd197d..85d9eb24bd 100644 --- a/java/com/google/gerrit/sshd/BaseCommand.java +++ b/java/com/google/gerrit/sshd/BaseCommand.java @@ -51,6 +51,7 @@ import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.StringWriter; import java.nio.charset.Charset; +import java.util.Arrays; import java.util.concurrent.Future; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.atomic.AtomicReference; @@ -356,7 +357,7 @@ public abstract class BaseCommand implements Command { } m.append(" during "); m.append(context.getCommandLine()); - logger.atSevere().withCause(e).log(m.toString()); + logCauseIfRelevant(e, m); } if (e instanceof Failure) { @@ -383,6 +384,20 @@ public abstract class BaseCommand implements Command { return 128; } + private void logCauseIfRelevant(Throwable e, StringBuilder message) { + String zeroLength = "length=0"; + String streamAlreadyClosed = "stream is already closed"; + boolean isZeroLength = false; + + if (streamAlreadyClosed.equals(e.getMessage())) { + StackTraceElement[] stackTrace = e.getStackTrace(); + isZeroLength = Arrays.stream(stackTrace).anyMatch(s -> s.toString().contains(zeroLength)); + } + if (!isZeroLength) { + logger.atSevere().withCause(e).log(message.toString()); + } + } + protected UnloggedFailure die(String msg) { return new UnloggedFailure(1, "fatal: " + msg); } |