Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring Web adapter throws ErrorEntryFreeException #1482

Closed
longtutengfei opened this issue May 14, 2020 · 5 comments
Closed

Spring Web adapter throws ErrorEntryFreeException #1482

longtutengfei opened this issue May 14, 2020 · 5 comments
Labels
integration/spring-cloud Issue related to Spring Cloud Alibaba integration kind/question Category issues related to questions or problems

Comments

@longtutengfei
Copy link

longtutengfei commented May 14, 2020

spring boot Controller 视图 模板文件不存在时报 com.alibaba.csp.sentinel.ErrorEntryFreeException: The order of entry exit can't be paired with the order of entry, current entry in context: </**>, but expected: </test3>

<java.version>1.8</java.version>
<spring.cloud.version>Hoxton.SR4</spring.cloud.version>
<spring-cloud-alibaba.version>2.2.1.RELEASE</spring-cloud-alibaba.version>
<spring-boot.version>2.2.1.RELEASE</spring-boot.version>
@Controller
@RequestMapping("/")
public class IndexController {

    @RequestMapping("/index.html")
    public String indexHtml(){
        return "/index.html";
    }

    @RequestMapping("/test")
    public String test(){
        return "/btl/index.html";
    }

}

/btl 文件夹下 不存 index.html 模板 访问http://localhost/test

2020-05-14 17:17:18.869 ERROR 19004 --- [nio-9000-exec-2] o.s.web.servlet.HandlerExecutionChain    : HandlerInterceptor.afterCompletion threw exception

com.alibaba.csp.sentinel.ErrorEntryFreeException: The order of entry exit can't be paired with the order of entry, current entry in context: </**>, but expected: </test3>
	at com.alibaba.csp.sentinel.CtEntry.exitForContext(CtEntry.java:80) ~[sentinel-core-1.7.1.jar:1.7.1]
	at com.alibaba.csp.sentinel.CtEntry.trueExit(CtEntry.java:108) ~[sentinel-core-1.7.1.jar:1.7.1]
	at com.alibaba.csp.sentinel.CtEntry.exit(CtEntry.java:61) ~[sentinel-core-1.7.1.jar:1.7.1]
	at com.alibaba.csp.sentinel.Entry.exit(Entry.java:79) ~[sentinel-core-1.7.1.jar:1.7.1]
	at com.alibaba.csp.sentinel.adapter.spring.webmvc.AbstractSentinelInterceptor.traceExceptionAndExit(AbstractSentinelInterceptor.java:122) ~[sentinel-spring-webmvc-adapter-1.7.1.jar:na]
	at com.alibaba.csp.sentinel.adapter.spring.webmvc.AbstractSentinelInterceptor.afterCompletion(AbstractSentinelInterceptor.java:87) ~[sentinel-spring-webmvc-adapter-1.7.1.jar:na]
	at org.springframework.web.servlet.HandlerExecutionChain.triggerAfterCompletion(HandlerExecutionChain.java:179) ~[spring-webmvc-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1136) [spring-webmvc-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1057) [spring-webmvc-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943) [spring-webmvc-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) [spring-webmvc-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) [spring-webmvc-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:634) [tomcat-embed-core-9.0.34.jar:9.0.34]
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) [spring-webmvc-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) [tomcat-embed-core-9.0.34.jar:9.0.34]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) [tomcat-embed-core-9.0.34.jar:9.0.34]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-9.0.34.jar:9.0.34]
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) [tomcat-embed-websocket-9.0.34.jar:9.0.34]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-9.0.34.jar:9.0.34]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-9.0.34.jar:9.0.34]
	at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:712) [tomcat-embed-core-9.0.34.jar:9.0.34]
	at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:459) [tomcat-embed-core-9.0.34.jar:9.0.34]
	at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:384) [tomcat-embed-core-9.0.34.jar:9.0.34]
	at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:312) [tomcat-embed-core-9.0.34.jar:9.0.34]
	at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:171) [spring-webmvc-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:316) [spring-webmvc-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1373) [spring-webmvc-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1118) [spring-webmvc-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1057) [spring-webmvc-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943) [spring-webmvc-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) [spring-webmvc-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) [spring-webmvc-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:634) [tomcat-embed-core-9.0.34.jar:9.0.34]
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) [spring-webmvc-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) [tomcat-embed-core-9.0.34.jar:9.0.34]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) [tomcat-embed-core-9.0.34.jar:9.0.34]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-9.0.34.jar:9.0.34]
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) [tomcat-embed-websocket-9.0.34.jar:9.0.34]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-9.0.34.jar:9.0.34]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-9.0.34.jar:9.0.34]
	at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) [spring-web-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) [spring-web-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-9.0.34.jar:9.0.34]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-9.0.34.jar:9.0.34]
	at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) [spring-web-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) [spring-web-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-9.0.34.jar:9.0.34]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-9.0.34.jar:9.0.34]
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) [spring-web-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) [spring-web-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-9.0.34.jar:9.0.34]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-9.0.34.jar:9.0.34]
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) [tomcat-embed-core-9.0.34.jar:9.0.34]
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [tomcat-embed-core-9.0.34.jar:9.0.34]
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541) [tomcat-embed-core-9.0.34.jar:9.0.34]
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) [tomcat-embed-core-9.0.34.jar:9.0.34]
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) [tomcat-embed-core-9.0.34.jar:9.0.34]
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) [tomcat-embed-core-9.0.34.jar:9.0.34]
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) [tomcat-embed-core-9.0.34.jar:9.0.34]
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:373) [tomcat-embed-core-9.0.34.jar:9.0.34]
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) [tomcat-embed-core-9.0.34.jar:9.0.34]
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) [tomcat-embed-core-9.0.34.jar:9.0.34]
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590) [tomcat-embed-core-9.0.34.jar:9.0.34]
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.34.jar:9.0.34]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_60]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_60]
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.34.jar:9.0.34]
	at java.lang.Thread.run(Thread.java:745) [na:1.8.0_60]
@cdfive
Copy link
Collaborator

cdfive commented May 14, 2020

Check if exists in log message:
... The attribute key '...' already exists in request, please set requestAttributeName``

The spring-cloud-starter-alibaba-sentinel has defined SentinelWebInterceptor, pay attention to not define it twice in your project.

Refer to #1392

@cdfive cdfive added integration/spring-cloud Issue related to Spring Cloud Alibaba integration kind/question Category issues related to questions or problems labels May 14, 2020
@longtutengfei
Copy link
Author

longtutengfei commented May 15, 2020

是的 csp log 出现了

2020-05-15 08:03:54.739 WARNING [{}] The attribute key '{0}' already exists in request, please set requestAttributeName

SentinelWebInterceptor 没有 出现在 项目配置,都是 用的默认的

经常访问这个 地址 http://localhost/test (有路由映射但是模板确实不存)这种情况 抛出这个 异常 不会影响 项目运行吧?

在举个例子 test4,test5 没有这个 路由映射(@RequestMapping("/test4")) 这种情况访问 就不会 抛出异常,单纯 模板不存的情况下 才抛出这个 异常
项目引用的包

<dependencies>    
      <dependency>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-web</artifactId>
       </dependency>

       <dependency>
           <groupId>com.alibaba.cloud</groupId>
           <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
       </dependency>
       <dependency>
           <groupId>com.alibaba.cloud</groupId>
           <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
       </dependency>
       <dependency>
           <groupId>com.alibaba.cloud</groupId>
           <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
       </dependency>
       <dependency>
           <groupId>com.ibeetl</groupId>
           <artifactId>beetl-framework-starter</artifactId>
           <version>${beetl.version}</version>
       </dependency>
       <dependency>
           <groupId>cn.hutool</groupId>
           <artifactId>hutool-all</artifactId>
           <version>${hutool.version}</version>
       </dependency>
<dependencies>

@cdfive
Copy link
Collaborator

cdfive commented May 15, 2020

If the template /btl/index.html is not exists, the AbstractSentinelInterceptor will enter twice, which leads to the exception.

Maybe in SentinelWebAutoConfiguration of spring-cloud-starter-alibaba-sentinel,

SentinelProperties.Filter filterConfig = properties.getFilter();
registry.addInterceptor(sentinelWebInterceptorOptional.get())
    .order(filterConfig.getOrder())
    .addPathPatterns(filterConfig.getUrlPatterns())
    .excludePathPatterns(xxx)

We may need exclude some path xxx for SentinelWebInterceptor, such as "/login","/logout" or static resources, maybe a new config parameter excluedPathPatterns is needed.

Another way to solve this is add custom UrlCleaner.

@Component
public class CustomUrlCleaner implements UrlCleaner {

    @Override
    public String clean(String originUrl) {
//        return originUrl.endsWith(".html") ? "" : originUrl;
        return originUrl.equals("/**") ? "" : originUrl;
    }
}

Note that the originUrl of /btl/index.html is /**, since SentinelWebInterceptor use HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE to resolve the Spring Web URL pattern from the request attribute.

Considering the above situation and html template resources, and don't want to limit the html resource, this is better:
return originUrl.equals("/**") || originUrl.endsWith(".html") ? "" : originUrl;

@sczyh30 sczyh30 changed the title spring boot Controller 视图 模板文件不存在时报 com.alibaba.csp.sentinel.ErrorEntryFreeException: The order of entry exit can't be paired with the order of entry, current entry in context: </**>, but expected: </test3> Spring Web adapter throws ErrorEntryFreeException May 19, 2020
@sczyh30
Copy link
Member

sczyh30 commented May 26, 2020

Any feedback?

@longtutengfei
Copy link
Author

谢谢 问题已解决

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration/spring-cloud Issue related to Spring Cloud Alibaba integration kind/question Category issues related to questions or problems
Projects
None yet
Development

No branches or pull requests

3 participants