Fix NPE in gateway plugin when the timer triggers webflux webclient call. (#164)

This commit is contained in:
wuwen 2022-04-25 09:28:27 +08:00 committed by GitHub
parent 81ded4acf5
commit 4d76f3e2fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 3 deletions

View File

@ -9,6 +9,7 @@ Release Notes.
* Add layer field to event when reporting.
* Remove redundant `shade.package` property.
* Add servicecomb-2.x plugin and Testcase.
* Fix NPE in gateway plugin when the timer triggers webflux webclient call.
#### Documentation

View File

@ -45,6 +45,16 @@ public class HttpClientRequestInterceptor implements InstanceMethodsAroundInterc
final Object[] allArguments,
final Class<?>[] argumentsTypes,
final MethodInterceptResult result) throws Throwable {
/*
In this plug-in, the HttpClientFinalizerSendInterceptor depends on the NettyRoutingFilterInterceptor
When the NettyRoutingFilterInterceptor is not executed, the HttpClientFinalizerSendInterceptor has no meaning to be executed independently
and using ContextManager.activeSpan() method would cause NPE as active span does not exist.
*/
if (!ContextManager.isActive()) {
return;
}
AbstractSpan span = ContextManager.activeSpan();
URL url = new URL((String) allArguments[1]);
@ -78,7 +88,7 @@ public class HttpClientRequestInterceptor implements InstanceMethodsAroundInterc
final Method method,
final Object[] allArguments,
final Class<?>[] argumentsTypes,
final Object ret) throws Throwable {
final Object ret) {
EnhanceCacheObject enhanceCacheObject = (EnhanceCacheObject) objInst.getSkyWalkingDynamicField();
Mono<HttpClientResponse> responseMono = (Mono<HttpClientResponse>) ret;
return responseMono.doAfterSuccessOrError(new BiConsumer<HttpClientResponse, Throwable>() {

View File

@ -42,6 +42,16 @@ public class HttpClientFinalizerSendInterceptor implements InstanceMethodsAround
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
MethodInterceptResult result) throws Throwable {
EnhanceObjectCache enhanceObjectCache = (EnhanceObjectCache) objInst.getSkyWalkingDynamicField();
/*
In this plug-in, the HttpClientFinalizerSendInterceptor depends on the NettyRoutingFilterInterceptor
When the NettyRoutingFilterInterceptor is not executed, the HttpClientFinalizerSendInterceptor has no meaning to be executed independently
and using ContextManager.activeSpan() method would cause NPE as active span does not exist.
*/
if (!ContextManager.isActive()) {
return;
}
AbstractSpan span = ContextManager.activeSpan();
span.prepareForAsync();
@ -85,7 +95,7 @@ public class HttpClientFinalizerSendInterceptor implements InstanceMethodsAround
@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
Object ret) throws Throwable {
Object ret) {
((EnhancedInstance) ret).setSkyWalkingDynamicField(objInst.getSkyWalkingDynamicField());
return ret;
}

View File

@ -53,6 +53,16 @@ public class HttpClientFinalizerSendInterceptor implements InstanceMethodsAround
if (enhanceObjectCache == null) {
return;
}
/*
In this plug-in, the HttpClientFinalizerSendInterceptor depends on the NettyRoutingFilterInterceptor
When the NettyRoutingFilterInterceptor is not executed, the HttpClientFinalizerSendInterceptor has no meaning to be executed independently
and using ContextManager.activeSpan() method would cause NPE as active span does not exist.
*/
if (!ContextManager.isActive()) {
return;
}
AbstractSpan span = ContextManager.activeSpan();
span.prepareForAsync();
@ -92,7 +102,7 @@ public class HttpClientFinalizerSendInterceptor implements InstanceMethodsAround
@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
Object ret) throws Throwable {
Object ret) {
((EnhancedInstance) ret).setSkyWalkingDynamicField(objInst.getSkyWalkingDynamicField());
return ret;
}