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 2018/05/17 10:07:28 UTC

[GitHub] candyleer opened a new issue #1238: NPE when use hystrix in spring

candyleer opened a new issue #1238: NPE when use hystrix in spring 
URL: https://github.com/apache/incubator-skywalking/issues/1238
 
 
   Please answer these questions before submitting your issue.
   
   - Why do you submit this issue?
   - [ ] Question or discussion
   - [x] Bug
   - [ ] Requirement
   - [ ] Feature or performance improvement
   
   ___
   ### Question
   - What do you want to know?
   
   ___
   ### Bug
   - Which version of SkyWalking, OS and JRE?
    5.0.0-beta
   - Which company or project?
   
   - What happen?
   If possible, provide a way for reproducing the error. e.g. demo application, component version.
   
   ```
   ERROR 2018-05-17 17:57:15 InstMethodsInter :  class[class com.example.test.TestApplication$$EnhancerBySpringCGLIB$$e3c93b0] before method[getUser] intercept failure
   java.lang.NullPointerException
   	at org.apache.skywalking.apm.plugin.spring.mvc.commons.interceptor.AbstractMethodInterceptor.beforeMethod(AbstractMethodInterceptor.java:57)
   	at org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstMethodsInter.intercept(InstMethodsInter.java:82)
   	at com.example.test.TestApplication.getUser(TestApplication.java)
   	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
   	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   	at java.lang.reflect.Method.invoke(Method.java:498)
   	at com.netflix.hystrix.contrib.javanica.command.MethodExecutionAction.execute(MethodExecutionAction.java:116)
   	at com.netflix.hystrix.contrib.javanica.command.MethodExecutionAction.executeWithArgs(MethodExecutionAction.java:93)
   	at com.netflix.hystrix.contrib.javanica.command.MethodExecutionAction.execute(MethodExecutionAction.java:78)
   	at com.netflix.hystrix.contrib.javanica.command.GenericCommand$1.execute(GenericCommand.java:48)
   	at com.netflix.hystrix.contrib.javanica.command.AbstractHystrixCommand.process(AbstractHystrixCommand.java:145)
   	at com.netflix.hystrix.contrib.javanica.command.GenericCommand.run$original$CdXtZRnv(GenericCommand.java:45)
   	at com.netflix.hystrix.contrib.javanica.command.GenericCommand.run$original$CdXtZRnv$accessor$q5odGkGX(GenericCommand.java)
   	at com.netflix.hystrix.contrib.javanica.command.GenericCommand$auxiliary$BVptRI6S.call(Unknown Source)
   	at org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstMethodsInter.intercept(InstMethodsInter.java:93)
   	at com.netflix.hystrix.contrib.javanica.command.GenericCommand.run(GenericCommand.java)
   	at com.netflix.hystrix.HystrixCommand$2.call(HystrixCommand.java:302)
   	at com.netflix.hystrix.HystrixCommand$2.call(HystrixCommand.java:298)
   	at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:46)
   	at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:35)
   	at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
   	at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
   	at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
   	at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
   	at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
   	at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
   	at rx.Observable.unsafeSubscribe(Observable.java:10151)
   	at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:51)
   	at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:35)
   	at rx.Observable.unsafeSubscribe(Observable.java:10151)
   	at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:41)
   	at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:30)
   	at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
   	at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
   	at rx.Observable.unsafeSubscribe(Observable.java:10151)
   	at rx.internal.operators.OperatorSubscribeOn$1.call(OperatorSubscribeOn.java:94)
   	at com.netflix.hystrix.strategy.concurrency.HystrixContexSchedulerAction$1.call(HystrixContexSchedulerAction.java:56)
   	at com.netflix.hystrix.strategy.concurrency.HystrixContexSchedulerAction$1.call(HystrixContexSchedulerAction.java:47)
   	at com.netflix.hystrix.strategy.concurrency.HystrixContexSchedulerAction.call(HystrixContexSchedulerAction.java:69)
   	at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)
   	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
   	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
   	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)
   
   DEBUG 2018-05-17 17:57:15 AppAndServiceRegisterClient :  AppAndServiceRegisterClient running, status:CONNECTED.
   ERROR 2018-05-17 17:57:17 InstMethodsInter :  class[class com.example.test.TestApplication$$EnhancerBySpringCGLIB$$e3c93b0] after method[getUser] intercept failure
   java.lang.NullPointerException
   	at org.apache.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache.getHttpServletResponse(EnhanceRequireObjectCache.java:36)
   	at org.apache.skywalking.apm.plugin.spring.mvc.commons.interceptor.AbstractMethodInterceptor.afterMethod(AbstractMethodInterceptor.java:77)
   	at org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstMethodsInter.intercept(InstMethodsInter.java:105)
   	at com.example.test.TestApplication.getUser(TestApplication.java)
   	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
   	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   	at java.lang.reflect.Method.invoke(Method.java:498)
   	at com.netflix.hystrix.contrib.javanica.command.MethodExecutionAction.execute(MethodExecutionAction.java:116)
   	at com.netflix.hystrix.contrib.javanica.command.MethodExecutionAction.executeWithArgs(MethodExecutionAction.java:93)
   	at com.netflix.hystrix.contrib.javanica.command.MethodExecutionAction.execute(MethodExecutionAction.java:78)
   	at com.netflix.hystrix.contrib.javanica.command.GenericCommand$1.execute(GenericCommand.java:48)
   	at com.netflix.hystrix.contrib.javanica.command.AbstractHystrixCommand.process(AbstractHystrixCommand.java:145)
   	at com.netflix.hystrix.contrib.javanica.command.GenericCommand.run$original$CdXtZRnv(GenericCommand.java:45)
   	at com.netflix.hystrix.contrib.javanica.command.GenericCommand.run$original$CdXtZRnv$accessor$q5odGkGX(GenericCommand.java)
   	at com.netflix.hystrix.contrib.javanica.command.GenericCommand$auxiliary$BVptRI6S.call(Unknown Source)
   	at org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstMethodsInter.intercept(InstMethodsInter.java:93)
   	at com.netflix.hystrix.contrib.javanica.command.GenericCommand.run(GenericCommand.java)
   	at com.netflix.hystrix.HystrixCommand$2.call(HystrixCommand.java:302)
   	at com.netflix.hystrix.HystrixCommand$2.call(HystrixCommand.java:298)
   	at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:46)
   	at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:35)
   	at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
   	at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
   	at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
   	at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
   	at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
   	at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
   	at rx.Observable.unsafeSubscribe(Observable.java:10151)
   	at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:51)
   	at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:35)
   	at rx.Observable.unsafeSubscribe(Observable.java:10151)
   	at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:41)
   	at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:30)
   	at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
   	at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
   	at rx.Observable.unsafeSubscribe(Observable.java:10151)
   	at rx.internal.operators.OperatorSubscribeOn$1.call(OperatorSubscribeOn.java:94)
   	at com.netflix.hystrix.strategy.concurrency.HystrixContexSchedulerAction$1.call(HystrixContexSchedulerAction.java:56)
   	at com.netflix.hystrix.strategy.concurrency.HystrixContexSchedulerAction$1.call(HystrixContexSchedulerAction.java:47)
   	at com.netflix.hystrix.strategy.concurrency.HystrixContexSchedulerAction.call(HystrixContexSchedulerAction.java:69)
   	at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)
   	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
   	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
   	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)
   ```
   
   demo
   ```
   @Autowired
       private RemoteService remoteService;
   
       @RequestMapping(value = "/user")
       @HystrixCommand(fallbackMethod = "fallback", threadPoolProperties = {
               @HystrixProperty(name = "coreSize", value = "30"), @HystrixProperty(name = "maxQueueSize", value = "100"),
               @HystrixProperty(name = "queueSizeRejectionThreshold", value = "20")}, commandProperties = {
               @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "3000"),
               @HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "1")
   
       })
       public Object getUser() throws InterruptedException {
           return remoteService.getUser();
       }
   ```
   
   ```
   /**
    * @author lican
    */
   @Configuration
   public class HystrixConfiguration {
       @Bean
       public HystrixCommandAspect hystrixAspect() {
           return new HystrixCommandAspect();
       }
   
       @Bean
       public ServletRegistrationBean hystrixMetricsStreamServlet() {
           ServletRegistrationBean registration = new ServletRegistrationBean(new HystrixMetricsStreamServlet());
           registration.addUrlMappings("/hystrix.stream");
           return registration;
       }
   
   }
   ```
   
   the cause is `(ServletRequestAttributes)RequestContextHolder.getRequestAttributes()` is null 
   the hystrix is in another thread which is different from `setRequestAttributes`
   ___
   ### Requirement or improvement
   - Please describe about your requirements or improvement suggestions.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services