You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by mm...@apache.org on 2018/01/25 02:19:58 UTC
[incubator-pulsar] branch master updated: Log only first exception
in the connection exception handler (#1107)
This is an automated email from the ASF dual-hosted git repository.
mmerli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pulsar.git
The following commit(s) were added to refs/heads/master by this push:
new f57cd88 Log only first exception in the connection exception handler (#1107)
f57cd88 is described below
commit f57cd88d82e4412d6031301bc1b1818b3a0cbcfe
Author: Matteo Merli <mm...@apache.org>
AuthorDate: Wed Jan 24 18:19:57 2018 -0800
Log only first exception in the connection exception handler (#1107)
---
.../apache/pulsar/broker/service/ServerCnx.java | 16 ++++++++++++++--
.../org/apache/pulsar/client/impl/ClientCnx.java | 22 ++++++++++++++++++++--
2 files changed, 34 insertions(+), 4 deletions(-)
diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
index df8e577..bd49fc7 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
@@ -44,6 +44,7 @@ import org.apache.pulsar.broker.service.BrokerServiceException.ServiceUnitNotRea
import org.apache.pulsar.broker.web.RestException;
import org.apache.pulsar.client.api.PulsarClientException;
import org.apache.pulsar.client.impl.BatchMessageIdImpl;
+import org.apache.pulsar.client.impl.ClientCnx;
import org.apache.pulsar.client.impl.MessageIdImpl;
import org.apache.pulsar.common.api.CommandUtils;
import org.apache.pulsar.common.api.Commands;
@@ -102,7 +103,7 @@ public class ServerCnx extends PulsarHandler {
private String originalPrincipal;
enum State {
- Start, Connected
+ Start, Connected, Failed
}
public ServerCnx(BrokerService service) {
@@ -164,7 +165,18 @@ public class ServerCnx extends PulsarHandler {
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
- log.warn("[{}] Got exception: {}", remoteAddress, cause.getMessage(), cause);
+ if (state != State.Failed) {
+ // No need to report stack trace for known exceptions that happen in disconnections
+ log.warn("[{}] Got exception {} : {}", remoteAddress, cause.getClass().getSimpleName(), cause.getMessage(),
+ ClientCnx.isKnownException(cause) ? null : cause);
+ state = State.Failed;
+ } else {
+ // At default info level, suppress all subsequent exceptions that are thrown when the connection has already
+ // failed
+ if (log.isDebugEnabled()) {
+ log.debug("[{}] Got exception: {}", remoteAddress, cause.getMessage(), cause);
+ }
+ }
ctx.close();
}
diff --git a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ClientCnx.java b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ClientCnx.java
index 2eaa1d4..85e2867 100644
--- a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ClientCnx.java
+++ b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ClientCnx.java
@@ -23,6 +23,7 @@ import static org.apache.pulsar.client.impl.HttpClient.getPulsarClientVersion;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
+import java.nio.channels.ClosedChannelException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
@@ -57,6 +58,7 @@ import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.EventLoopGroup;
+import io.netty.channel.unix.Errors.NativeIoException;
import io.netty.util.concurrent.Promise;
public class ClientCnx extends PulsarHandler {
@@ -85,7 +87,7 @@ public class ClientCnx extends PulsarHandler {
private String proxyToTargetBrokerAddress = null;
enum State {
- None, SentConnectFrame, Ready
+ None, SentConnectFrame, Ready, Failed
}
public ClientCnx(ClientConfiguration conf, EventLoopGroup eventLoopGroup) {
@@ -152,10 +154,26 @@ public class ClientCnx extends PulsarHandler {
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
- log.warn("{} Exception caught: {}", ctx.channel(), cause.getMessage(), cause);
+ if (state != State.Failed) {
+ // No need to report stack trace for known exceptions that happen in disconnections
+ log.warn("[{}] Got exception {} : {}", remoteAddress, cause.getClass().getSimpleName(), cause.getMessage(),
+ isKnownException(cause) ? null : cause);
+ state = State.Failed;
+ } else {
+ // At default info level, suppress all subsequent exceptions that are thrown when the connection has already
+ // failed
+ if (log.isDebugEnabled()) {
+ log.debug("[{}] Got exception: {}", remoteAddress, cause.getMessage(), cause);
+ }
+ }
+
ctx.close();
}
+ public static boolean isKnownException(Throwable t) {
+ return t instanceof NativeIoException || t instanceof ClosedChannelException;
+ }
+
@Override
protected void handleConnected(CommandConnected connected) {
checkArgument(state == State.SentConnectFrame);
--
To stop receiving notification emails like this one, please contact
mmerli@apache.org.