You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2022/04/24 06:19:01 UTC

[GitHub] [skywalking-java] wuwen5 opened a new pull request, #164: Fix NPE in gateway plugin when the timer triggers webflux webclient call

wuwen5 opened a new pull request, #164:
URL: https://github.com/apache/skywalking-java/pull/164

   Fixed #6967
   
   
   The scene I met
   ```
   ERROR 2022-04-22 00:00:08:948 registrationTask1 InstMethodsInterWithOverrideArgs : class[class reactor.netty.http.client.HttpClientFinalizer] before method[[
   send] intercept failure
   java.lang.NullPointerException
           at org.apache.skywalking.apm.agent.core.context.ContextManager.activeSpan(ContextManager.java:176)
           at org.apache.skywalking.apm.plugin.spring.cloud.gateway.v3x.HttpClientFinalizerSendInterceptor.beforeMethod(HttpClientFinalizerSendInterceptor.javaa
   :56)
           at org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstMethodsInterWithOverrideArgs.intercept(InstMethodsInterWithOverrideArgs.java::
   75)
           at reactor.netty.http.client.HttpClientFinalizer.send(HttpClientFinalizer.java)
           at reactor.netty.http.client.HttpClientFinalizer.send(HttpClientFinalizer.java:45)
           at org.springframework.http.client.reactive.ReactorClientHttpConnector.connect(ReactorClientHttpConnector.java:111)
           at org.springframework.web.reactive.function.client.ExchangeFunctions$DefaultExchangeFunction.exchange$original$rFJ45LhK(ExchangeFunctions.java:103)
           at org.springframework.web.reactive.function.client.ExchangeFunctions$DefaultExchangeFunction.exchange$original$rFJ45LhK$accessor$sIxgheaU(ExchangeFF
   unctions.java)
           at org.springframework.web.reactive.function.client.ExchangeFunctions$DefaultExchangeFunction$auxiliary$U3wHWPOg.call(Unknown Source)
           at org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.v2.InstMethodsInterV2.intercept(InstMethodsInterV2.java:67)
           at org.springframework.web.reactive.function.client.ExchangeFunctions$DefaultExchangeFunction.exchange(ExchangeFunctions.java)
           at org.springframework.cloud.client.loadbalancer.reactive.ReactorLoadBalancerExchangeFilterFunction.lambda$filter$7(ReactorLoadBalancerExchangeFiltee
   rFunction.java:128)
           at reactor.core.publisher.MonoFlatMap$FlatMapMain.onNext(MonoFlatMap.java:125)
           at reactor.core.publisher.FluxSubscribeOn$SubscribeOnSubscriber.requestUpstream(FluxSubscribeOn.java:131)
           at reactor.core.publisher.FluxSubscribeOn$SubscribeOnSubscriber.onSubscribe(FluxSubscribeOn.java:124)
           at reactor.core.publisher.FluxIterable.subscribe(FluxIterable.java:165)
           at reactor.core.publisher.FluxIterable.subscribe(FluxIterable.java:87)
           at reactor.core.publisher.Flux.subscribe(Flux.java:8469)
           at reactor.core.publisher.FluxFlatMap.trySubscribeScalarMap(FluxFlatMap.java:200)
           at reactor.core.publisher.MonoFlatMapMany.subscribeOrReturn(MonoFlatMapMany.java:49)
           at reactor.core.publisher.FluxFromMonoOperator.subscribe(FluxFromMonoOperator.java:76)
           at reactor.core.publisher.FluxSubscribeOn$SubscribeOnSubscriber.run(FluxSubscribeOn.java:194)
           at reactor.core.scheduler.WorkerTask.call(WorkerTask.java:84)
           at reactor.core.scheduler.WorkerTask.call(WorkerTask.java:37)
           at java.util.concurrent.FutureTask.run(FutureTask.java:266)
           at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
           at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
           at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
           at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
           at java.lang.Thread.run(Thread.java:745)
   ```
   
   In #6967 case, it is also triggered by timer.
   ```
   java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
   at java.lang.Thread.run(Thread.java:748)
   ```
   
   I think the ```HttpClientFinalizerSendInterceptor``` should depend on the ```NettyRoutingFilterInterceptor```
   When there is no RoutingFilter,  the ```HttpClientFinalizerSendInterceptor``` has no meaning to be executed separately
   
   We can handle this client-side call through the ```weblux-webclient``` plug-in
   
   <!--
       ⚠️ Please make sure to read this template first, pull requests that don't accord with this template
       maybe closed without notice.
       Texts surrounded by `<` and `>` are meant to be replaced by you, e.g. <framework name>, <issue number>.
       Put an `x` in the `[ ]` to mark the item as CHECKED. `[x]`
   -->
   
   <!-- ==== 🐛 Remove this line WHEN AND ONLY WHEN you're fixing a bug, follow the checklist 👇 ====
   ### Fix <bug description or the bug issue number or bug issue link>
   - [ ] Add a unit test to verify that the fix works.
   - [ ] Explain briefly why the bug exists and how to fix it.
        ==== 🐛 Remove this line WHEN AND ONLY WHEN you're fixing a bug, follow the checklist 👆 ==== -->
   
   <!-- ==== 🔌 Remove this line WHEN AND ONLY WHEN you're adding a new plugin, follow the checklist 👇 ====
   ### Add an agent plugin to support <framework name>
   - [ ] Add a test case for the new plugin, refer to [the doc](https://github.com/apache/skywalking-java/blob/main/docs/en/setup/service-agent/java-agent/Plugin-test.md)
   - [ ] Add a component id in [the component-libraries.yml](https://github.com/apache/skywalking/blob/master/oap-server/server-starter/src/main/resources/component-libraries.yml)
   - [ ] Add a logo in [the UI repo](https://github.com/apache/skywalking-rocketbot-ui/tree/master/src/views/components/topology/assets)
        ==== 🔌 Remove this line WHEN AND ONLY WHEN you're adding a new plugin, follow the checklist 👆 ==== -->
   
   <!-- ==== 📈 Remove this line WHEN AND ONLY WHEN you're improving the performance, follow the checklist 👇 ====
   ### Improve the performance of <class or module or ...>
   - [ ] Add a benchmark for the improvement, refer to [the existing ones](https://github.com/apache/skywalking-java/blob/main/apm-commons/apm-datacarrier/src/test/java/org/apache/skywalking/apm/commons/datacarrier/LinkedArrayBenchmark.java)
   - [ ] The benchmark result.
   ```text
   <Paste the benchmark results here>
   ```
   - [ ] Links/URLs to the theory proof or discussion articles/blogs. <links/URLs here>
        ==== 📈 Remove this line WHEN AND ONLY WHEN you're improving the performance, follow the checklist 👆 ==== -->
   
   <!-- ==== 🆕 Remove this line WHEN AND ONLY WHEN you're adding a new feature, follow the checklist 👇 ====
   ### <Feature description>
   - [ ] If this is non-trivial feature, paste the links/URLs to the design doc.
   - [ ] Update the documentation to include this new feature.
   - [ ] Tests(including UT, IT, E2E) are added to verify the new feature.
   - [ ] If it's UI related, attach the screenshots below.
        ==== 🆕 Remove this line WHEN AND ONLY WHEN you're adding a new feature, follow the checklist 👆 ==== -->
   
   - [x] If this pull request closes/resolves/fixes an existing issue, replace the issue number. Closes #<issue number>.
   - [x] Update the [`CHANGES` log](https://github.com/apache/skywalking-java/blob/main/CHANGES.md).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [skywalking-java] wu-sheng commented on a diff in pull request #164: Fix NPE in gateway plugin when the timer triggers webflux webclient call

Posted by GitBox <gi...@apache.org>.
wu-sheng commented on code in PR #164:
URL: https://github.com/apache/skywalking-java/pull/164#discussion_r857100030


##########
apm-sniffer/optional-plugins/optional-spring-plugins/optional-spring-cloud/gateway-2.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/cloud/gateway/v20x/HttpClientRequestInterceptor.java:
##########
@@ -45,6 +45,11 @@ public void beforeMethod(final EnhancedInstance objInst,
                              final Object[] allArguments,
                              final Class<?>[] argumentsTypes,
                              final MethodInterceptResult result) throws Throwable {
+        
+        if (!ContextManager.isActive()) {
+            return;
+        }

Review Comment:
   Please give a clear comment at here about what are the cases there is no active context. 
   
   I know you mentioned it in the PR description, but you should put a formal one here and others too.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [skywalking-java] wu-sheng commented on a diff in pull request #164: Fix NPE in gateway plugin when the timer triggers webflux webclient call

Posted by GitBox <gi...@apache.org>.
wu-sheng commented on code in PR #164:
URL: https://github.com/apache/skywalking-java/pull/164#discussion_r857117224


##########
apm-sniffer/optional-plugins/optional-spring-plugins/optional-spring-cloud/gateway-2.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/cloud/gateway/v20x/HttpClientRequestInterceptor.java:
##########
@@ -45,6 +45,16 @@ public void beforeMethod(final EnhancedInstance objInst,
                              final Object[] allArguments,
                              final Class<?>[] argumentsTypes,
                              final MethodInterceptResult result) throws Throwable {
+        
+        /*
+          In this plug-in the HttpClientFinalizerSendInterceptor depend on the NettyRoutingFilterInterceptor
+          When the NettyRoutingFilterInterceptor is not executed, the HttpClientFinalizerSendInterceptor has no meaning to be executed separately
+          and using ContextManager.activeSpan() method will cause NPE if active span does not exist.

Review Comment:
   ```suggestion
             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.
   ```
   
   Please fix other comments accordingly.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [skywalking-java] wu-sheng merged pull request #164: Fix NPE in gateway plugin when the timer triggers webflux webclient call

Posted by GitBox <gi...@apache.org>.
wu-sheng merged PR #164:
URL: https://github.com/apache/skywalking-java/pull/164


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org