Hystrix icon indicating copy to clipboard operation
Hystrix copied to clipboard

Hystrix synchronous fallback does not work with extended fallback (with throwable parameter)

Open shivangshah opened this issue 10 years ago • 7 comments

Hi,

I have added a test case here: https://github.com/shivangshah/test-service/blob/master/src/test/java/com/shivang/authentication/tests/AuthenticationResourceTest.java

Currently the test case fails because of the "throwable" parameter in the corresponding service here: https://github.com/shivangshah/test-service/blob/master/src/main/java/com/shivang/authentication/services/AuthenticationService.java

If I remove the "throwable" parameter and make the fallback signature exactly the same, it works fine (remove throwable and run the test case again). Not sure if it's something related to my configuration or an actual bug.

I also noticed thread weirdness as mentioned in #1011 when adding cascading synchronous fallbacks (I can add the test cases if need be) while I was debugging my test case. I will continue watching that issue.

Complete source code here: https://github.com/shivangshah/test-service

shivangshah avatar Dec 08 '15 06:12 shivangshah

@dmgcodevil I believe this might be related to how javanica wires together exceptions. Can you take a look?

mattrjacobs avatar Dec 09 '15 07:12 mattrjacobs

Yes. @shivangshah, what javanica version do you use ? I have tests for this feature in javanica and they passing. Could you provide exception stack trace or any logs. I would help a lot. About threads and fallbacks, frankly I didn't get what is the problem, I know what thread pool exhausted but have no idea that can lead to this.

dmgcodevil avatar Dec 09 '15 14:12 dmgcodevil

My hystrix core and javanica versions are 1.4.10. Here's a debug log that I feel is relevant

com.shivang.authentication.tests.AuthenticationResourceTest > testAuthenticate STANDARD_OUT
    [DEBUG]-[09 Dec 2015;16:32:45.022]-[TestRestTemplate:createRequest:78] - Created POST request for "http://localhost:9000/authentication-service/authenticate" 
    [DEBUG]-[09 Dec 2015;16:32:45.051]-[TestRestTemplate:doWithRequest:693] - Setting request Accept header to [application/json, application/*+json] 
    [DEBUG]-[09 Dec 2015;16:32:45.051]-[TestRestTemplate:doWithRequest:770] - Writing [{username=[username], password=[password]}] using [org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter@78faf637] 
    [DEBUG]-[09 Dec 2015;16:32:45.072]-[RequestAddCookies:process:122] - CookieSpec selected: ignoreCookies 
    [DEBUG]-[09 Dec 2015;16:32:45.078]-[RequestAuthCache:process:75] - Auth cache not set in the context 
    [DEBUG]-[09 Dec 2015;16:32:45.083]-[PoolingHttpClientConnectionManager:requestConnection:219] - Connection request: [route: {}->http://localhost:9000][total kept alive: 0; route allocated: 0 of 5; total allocated: 0 of 10] 
    [DEBUG]-[09 Dec 2015;16:32:45.110]-[PoolingHttpClientConnectionManager:leaseConnection:250] - Connection leased: [id: 0][route: {}->http://localhost:9000][total kept alive: 0; route allocated: 1 of 5; total allocated: 1 of 10] 
    [DEBUG]-[09 Dec 2015;16:32:45.113]-[MainClientExec:execute:217] - Opening connection {}->http://localhost:9000 
    [DEBUG]-[09 Dec 2015;16:32:45.125]-[HttpClientConnectionOperator:connect:122] - Connecting to localhost/127.0.0.1:9000 
    [DEBUG]-[09 Dec 2015;16:32:45.127]-[HttpClientConnectionOperator:connect:129] - Connection established 127.0.0.1:51493<->127.0.0.1:9000 
    [DEBUG]-[09 Dec 2015;16:32:45.127]-[MainClientExec:execute:238] - Executing request POST /authentication-service/authenticate HTTP/1.1 
    [DEBUG]-[09 Dec 2015;16:32:45.128]-[MainClientExec:execute:243] - Target auth state: UNCHALLENGED 
    [DEBUG]-[09 Dec 2015;16:32:45.128]-[MainClientExec:execute:249] - Proxy auth state: UNCHALLENGED 
    [DEBUG]-[09 Dec 2015;16:32:45.135]-[headers:onRequestSubmitted:124] - http-outgoing-0 >> POST /authentication-service/authenticate HTTP/1.1 
    [DEBUG]-[09 Dec 2015;16:32:45.136]-[headers:onRequestSubmitted:127] - http-outgoing-0 >> Accept: application/json, application/*+json 
    [DEBUG]-[09 Dec 2015;16:32:45.136]-[headers:onRequestSubmitted:127] - http-outgoing-0 >> Content-Type: application/x-www-form-urlencoded 
    [DEBUG]-[09 Dec 2015;16:32:45.137]-[headers:onRequestSubmitted:127] - http-outgoing-0 >> Content-Length: 35 
    [DEBUG]-[09 Dec 2015;16:32:45.137]-[headers:onRequestSubmitted:127] - http-outgoing-0 >> Host: localhost:9000 
    [DEBUG]-[09 Dec 2015;16:32:45.138]-[headers:onRequestSubmitted:127] - http-outgoing-0 >> Connection: Keep-Alive 
    [DEBUG]-[09 Dec 2015;16:32:45.138]-[headers:onRequestSubmitted:127] - http-outgoing-0 >> User-Agent: Apache-HttpClient/4.3.6 (java 1.5) 
    [DEBUG]-[09 Dec 2015;16:32:45.139]-[headers:onRequestSubmitted:127] - http-outgoing-0 >> Accept-Encoding: gzip,deflate 
    [DEBUG]-[09 Dec 2015;16:32:45.139]-[wire:wire:72] - http-outgoing-0 >> "POST /authentication-service/authenticate HTTP/1.1[\r][\n]" 
    [DEBUG]-[09 Dec 2015;16:32:45.140]-[wire:wire:72] - http-outgoing-0 >> "Accept: application/json, application/*+json[\r][\n]" 
    [DEBUG]-[09 Dec 2015;16:32:45.140]-[wire:wire:72] - http-outgoing-0 >> "Content-Type: application/x-www-form-urlencoded[\r][\n]" 
    [DEBUG]-[09 Dec 2015;16:32:45.140]-[wire:wire:72] - http-outgoing-0 >> "Content-Length: 35[\r][\n]" 
    [DEBUG]-[09 Dec 2015;16:32:45.141]-[wire:wire:72] - http-outgoing-0 >> "Host: localhost:9000[\r][\n]" 
    [DEBUG]-[09 Dec 2015;16:32:45.141]-[wire:wire:72] - http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]" 
    [DEBUG]-[09 Dec 2015;16:32:45.141]-[wire:wire:72] - http-outgoing-0 >> "User-Agent: Apache-HttpClient/4.3.6 (java 1.5)[\r][\n]" 
    [DEBUG]-[09 Dec 2015;16:32:45.141]-[wire:wire:72] - http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]" 
    [DEBUG]-[09 Dec 2015;16:32:45.141]-[wire:wire:72] - http-outgoing-0 >> "[\r][\n]" 
    [DEBUG]-[09 Dec 2015;16:32:45.143]-[wire:wire:86] - http-outgoing-0 >> "username=username&password=password" 
    [DEBUG]-[09 Dec 2015;16:32:46.170]-[RequestContextFilter:initContextHolders:114] - Bound request context to thread: org.apache.catalina.connector.RequestFacade@66de6012 
    [DEBUG]-[09 Dec 2015;16:32:46.174]-[DefaultListableBeanFactory:doGetBean:248] - Returning cached instance of singleton bean 'managementServerProperties' 
    [WARN ]-[09 Dec 2015;16:32:46.211]-[WebComponent:filterFormParameters:564] - A servlet request to the URI http://localhost:9000/authentication-service/authenticate contains form parameters in the request body but the request body has been consumed by the servlet or a servlet filter accessing the request parameters. Only resource methods using @FormParam will work as expected. Resource methods consuming the request body by other means will not work as expected. 
    [DEBUG]-[09 Dec 2015;16:32:46.233]-[DefaultListableBeanFactory:doGetBean:248] - Returning cached instance of singleton bean 'baseResource' 
    [DEBUG]-[09 Dec 2015;16:32:46.237]-[DefaultListableBeanFactory:doGetBean:248] - Returning cached instance of singleton bean 'authenticationService' 
    [DEBUG]-[09 Dec 2015;16:32:46.263]-[DefaultTraversableResolver:detectJPA:80] - Cannot find javax.persistence.Persistence on classpath. Assuming non JPA 2 environment. All properties will per default be traversable. 
    [DEBUG]-[09 Dec 2015;16:32:46.265]-[ValidationXmlParser:getInputStream:91] - Trying to load META-INF/validation.xml for XML based Validator configuration. 
    [DEBUG]-[09 Dec 2015;16:32:46.266]-[ValidationXmlParser:getInputStream:98] - No META-INF/validation.xml found. Using annotation based configuration only. 
    [DEBUG]-[09 Dec 2015;16:32:46.299]-[DefaultListableBeanFactory:doGetBean:248] - Returning cached instance of singleton bean 'hystrixCommandAspect' 
    [DEBUG]-[09 Dec 2015;16:32:46.328]-[RequestContextFilter:doFilterInternal:104] - Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@66de6012 
    [ERROR]-[09 Dec 2015;16:32:46.333]-[[jerseyServlet]:log:182] - Servlet.service() for servlet [jerseyServlet] in context with path [] threw exception [java.lang.RuntimeException: java.lang.NoSuchMethodException: com.shivang.authentication.services.AuthenticationService.authenticationFallback(java.lang.String, java.lang.String)] with root cause java.lang.NoSuchMethodException: com.shivang.authentication.services.AuthenticationService.authenticationFallback(java.lang.String, java.lang.String)
        at java.lang.Class.getDeclaredMethod(Class.java:2130)
        at com.netflix.hystrix.contrib.javanica.command.AbstractHystrixCommandFactory.createFallbackAction(AbstractHystrixCommandFactory.java:87)
        at com.netflix.hystrix.contrib.javanica.command.AbstractHystrixCommandFactory.create(AbstractHystrixCommandFactory.java:66)
        at com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect.methodsAnnotatedWithHystrixCommand(HystrixCommandAspect.java:81)
        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:497)
        at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621)
        at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610)
        at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:68)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:168)
        at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
        at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:653)
        at com.shivang.authentication.services.AuthenticationService$$EnhancerBySpringCGLIB$$83b579e.authenticate(<generated>)
        at com.shivang.authentication.resources.AuthenticationResource.authenticate(AuthenticationResource.java:34)
        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:497)
        at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)
        at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:151)
        at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:172)
        at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:152)
        at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:104)
        at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:384)
        at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:342)
        at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:101)
        at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:271)
        at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
        at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
        at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:297)
        at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:254)
        at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1030)
        at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:377)
        at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:381)
        at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:344)
        at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:221)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration$ApplicationContextHeaderFilter.doFilterInternal(EndpointWebMvcAutoConfiguration.java:295)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.springframework.boot.actuate.trace.WebRequestTraceFilter.doFilterInternal(WebRequestTraceFilter.java:102)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:85)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.springframework.boot.actuate.autoconfigure.MetricsFilter.doFilterInternal(MetricsFilter.java:69)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1526)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1482)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Thread.java:745)

The above exception does make sense atleast because it's trying to look for the fallback method WITHOUT the Throwable parameter. I am going to change the default to debug in my attached code repo as well so if you run it, you can see it as well.

And I will also add a test case where you will see the thread behavior that I am talking about. Basically if you have cascading fallbacks and they are called one after the other, and if you put a debug point in one of them, the later call continues and the tests sometimes fail. I was assuming that if they fallback is synchronous than the actual calls are synchronous as well and that hystrix fallback will be on the main thread itself. Seems like it's not. Not sure if this is by design.

shivangshah avatar Dec 09 '15 16:12 shivangshah

And ... I just checked. 1.4.10 is really old version. Problem was I was using angel.sr4 version of spring cloud starter parent which i just changed to brixton.M3 and it pulled 1.4.20 which passes the test just fine. Seems like it got fixed in the later versions ! thank you for all your help!

shivangshah avatar Dec 09 '15 16:12 shivangshah

If you annotated your fallback method with command annotation then it will be ran in separate thread otherwise in the command thread, it's as far as I know. Yes, log is very verbose, could you shrink it ?

dmgcodevil avatar Dec 09 '15 17:12 dmgcodevil

@dmgcodevil it's fixed after I upgraded the version. Thanks for the feedback!

shivangshah avatar Dec 09 '15 18:12 shivangshah

@shivangshah / @dmgcodevil Thanks for chasing this down. Any more to discuss in this issue, or may I close it?

mattrjacobs avatar Dec 09 '15 19:12 mattrjacobs