Add sonar.log-netty-exceptions flag

This commit is contained in:
Jones committed 2026-02-26 20:07:22 +01:00
1 parent cab082cdd5
commit 8be3d974e4
2 files changed
+9

No files matched your search

@@ -25,6 +25,7 @@ import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.jetbrains.annotations.NotNull;
import xyz.jonesdev.sonar.api.Sonar;
import xyz.jonesdev.sonar.common.netty.TailExceptionsHandler;
import xyz.jonesdev.sonar.common.statistics.GlobalSonarStatistics;
import java.net.InetAddress;
@@ -85,5 +86,8 @@ public final class InboundHandler extends ChannelInboundHandlerAdapter {
@Override
public void exceptionCaught(final @NotNull ChannelHandlerContext ctx, final Throwable cause) throws Exception {
ctx.close();
if (TailExceptionsHandler.LOG_EXCEPTIONS) {
cause.printStackTrace(System.err);
}
}
}
@@ -25,6 +25,8 @@ import org.jetbrains.annotations.NotNull;
@ChannelHandler.Sharable
public final class TailExceptionsHandler extends ChannelDuplexHandler {
public static final TailExceptionsHandler INSTANCE = new TailExceptionsHandler();
// Do not enable unless instructed by support.
public static final boolean LOG_EXCEPTIONS = Boolean.getBoolean("sonar.log-netty-exceptions");
// We can override the default exceptionCaught method since the server
// does not have any other pipelines that could handle this error.
@@ -33,5 +35,8 @@ public final class TailExceptionsHandler extends ChannelDuplexHandler {
public void exceptionCaught(final @NotNull ChannelHandlerContext ctx, final Throwable cause) throws Exception {
// Close the channel if we encounter any errors.
ctx.close();
if (LOG_EXCEPTIONS) {
cause.printStackTrace(System.err);
}
}
}