skywalking Hystrix插件产生异常被熔断

##skywalking Hystrix插件产生异常被熔断(sw-6.4.0版本)

1.方法产生异常

org.apache.skywalking.apm.plugin.redisson.v3.RedisConnectionMethodInterceptor#beforeMethod

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
MethodInterceptResult result) throws Throwable {
//在redisson SingleServerConfig该配置下,peer为null
String peer = (String) objInst.getSkyWalkingDynamicField();

RedisConnection connection = (RedisConnection) objInst;
Channel channel = connection.getChannel();
InetSocketAddress remoteAddress = (InetSocketAddress) channel.remoteAddress();
String dbInstance = remoteAddress.getAddress().getHostAddress() + ":" + remoteAddress.getPort();

StringBuilder dbStatement = new StringBuilder();
String operationName = "Redisson/";

if (allArguments[0] instanceof CommandsData) {
operationName = operationName + "BATCH_EXECUTE";
CommandsData commands = (CommandsData) allArguments[0];
for (CommandData commandData : commands.getCommands()) {
addCommandData(dbStatement, commandData);
dbStatement.append(";");
}
} else if (allArguments[0] instanceof CommandData) {
CommandData commandData = (CommandData) allArguments[0];
String command = commandData.getCommand().getName();
operationName = operationName + command;
addCommandData(dbStatement, commandData);
}

AbstractSpan span = ContextManager.createExitSpan(operationName, peer);
span.setComponent(ComponentsDefine.REDISSON);
Tags.DB_TYPE.set(span, "Redis");
Tags.DB_INSTANCE.set(span, dbInstance);
Tags.DB_STATEMENT.set(span, dbStatement.toString());
SpanLayer.asCache(span);
}

2.此处peer为null,导致在org.apache.skywalking.apm.agent.core.context.ContextManager#createExitSpan(java.lang.String, java.lang.String)该类中,创建了AbstractTracerContext并与thread进行了绑定。但是在org.apache.skywalking.apm.agent.core.context.AbstractTracerContext#createExitSpan过程中并未成功创建AbstractSpan,所以在此后的org.apache.skywalking.apm.agent.core.context.ContextManager#stopSpan()方法中也抛出异常,导致在该线程上进行ContextManager.isActive()判断为true,但是调用ContextManager.capture()就发生异常。

1
2
3
4
5
6
7
8
9
10
11
12
13
public <T> void onStart(HystrixInvokable<T> commandInstance) {
if (!(commandInstance instanceof EnhancedInstance)) {
actual.onStart(commandInstance);
return;
}

EnhancedInstance enhancedInstance = (EnhancedInstance)commandInstance;
EnhanceRequireObjectCache enhanceRequireObjectCache = (EnhanceRequireObjectCache)enhancedInstance.getSkyWalkingDynamicField();
if (ContextManager.isActive()) {
enhanceRequireObjectCache.setContextSnapshot(ContextManager.capture());
}
actual.onStart(commandInstance);
}

这也是在我这里引起Hystrix插件抛出异常被Hystrix异常熔断的原因

3.社区反馈

image-20200505153314711

技颠 wechat
欢迎您扫一扫上面的微信公众号,订阅我的微信公众号!