Skip to content

Commit

Permalink
Catch some harmless exception
Browse files Browse the repository at this point in the history
  • Loading branch information
earthchen committed Sep 2, 2021
1 parent b8de0a7 commit 635b7c3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,14 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
logger.warn(String.format("Channel:%s Error", ctx.channel()), cause);
// this may be change in future follow https://github.com/apache/dubbo/pull/8644
if (TripleUtil.isQuiteException(cause)) {
if (logger.isDebugEnabled()) {
logger.debug(String.format("Channel:%s Error", ctx.channel()), cause);
}
} else {
logger.warn(String.format("Channel:%s Error", ctx.channel()), cause);
}
ctx.close();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@
*/
package org.apache.dubbo.rpc.protocol.tri;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.serialize.MultipleSerialization;
import org.apache.dubbo.remoting.Constants;
import org.apache.dubbo.rpc.RpcInvocation;
import org.apache.dubbo.rpc.model.MethodDescriptor;
import org.apache.dubbo.triple.TripleWrapper;

import com.google.protobuf.Any;
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
Expand All @@ -37,17 +30,26 @@
import io.netty.handler.codec.http2.DefaultHttp2HeadersFrame;
import io.netty.handler.codec.http2.Http2Headers;
import io.netty.util.AttributeKey;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.serialize.MultipleSerialization;
import org.apache.dubbo.remoting.Constants;
import org.apache.dubbo.rpc.RpcInvocation;
import org.apache.dubbo.rpc.model.MethodDescriptor;
import org.apache.dubbo.triple.TripleWrapper;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.net.SocketException;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import static io.netty.handler.codec.http.HttpResponseStatus.OK;

Expand All @@ -58,6 +60,27 @@ public class TripleUtil {
public static final AttributeKey<AbstractClientStream> CLIENT_STREAM_KEY = AttributeKey.newInstance(
"tri_client_stream");

// Some exceptions are not very useful and add too much noise to the log
private static final Set<String> QUIET_EXCEPTIONS = new HashSet<>();
private static final Set<Class<?>> QUIET_EXCEPTIONS_CLASS = new HashSet<>();

static {
QUIET_EXCEPTIONS.add("NativeIoException");
QUIET_EXCEPTIONS_CLASS.add(IOException.class);
QUIET_EXCEPTIONS_CLASS.add(SocketException.class);
}

public static boolean isQuiteException(Throwable t) {
if (QUIET_EXCEPTIONS_CLASS.contains(t.getClass())) {
return true;
}
if (QUIET_EXCEPTIONS.contains(t.getClass().getSimpleName())) {
return true;
}
return false;
}


public static final String LANGUAGE = "java";

private static final Base64.Decoder BASE64_DECODER = Base64.getDecoder();
Expand Down

0 comments on commit 635b7c3

Please sign in to comment.