Sentinel icon indicating copy to clipboard operation
Sentinel copied to clipboard

ahas集成到zuul1.x网关限流后没有抛出ZuulException,导致无法进入Zuul的异常处理过滤器SendErrorFilter

Open stickgoal opened this issue 5 years ago • 1 comments

Issue Description

Type: bug report

Describe what happened (or what feature you want)

ahas与zuul1.x集成实现网关限流。如果被限流,抛出BlockException之后,没有抛出ZuulException,因而无法进入Zuul的错误处理流程。 代码在:com.alibaba.csp.sentinel.adapter.gateway.zuul.filters.SentinelZuulPreFilter#run 95-103行

 } catch (BlockException var12) {
            ZuulBlockFallbackProvider zuulBlockFallbackProvider = ZuulBlockFallbackManager.getFallbackProvider(fallBackRoute);
            BlockResponse blockResponse = zuulBlockFallbackProvider.fallbackResponse(fallBackRoute, var12);
            ctx.setRouteHost((URL)null);
            ctx.set("serviceId", (Object)null);
            ctx.setResponseBody(blockResponse.toString());
            ctx.setResponseStatusCode(blockResponse.getCode());
            ctx.getResponse().setContentType("application/json; charset=utf-8");
        } 

Describe what you expected to happen

限流完成后抛出一个Zuul异常

catch (BlockException e) {
            ZuulBlockFallbackProvider zuulBlockFallbackProvider = ZuulBlockFallbackManager.getFallbackProvider(fallBackRoute);
            BlockResponse blockResponse = zuulBlockFallbackProvider.fallbackResponse(fallBackRoute, var12);
            ctx.setRouteHost((URL)null);
            ctx.set("serviceId", (Object)null);
            ctx.setResponseBody(blockResponse.toString());
            ctx.setResponseStatusCode(blockResponse.getCode());
            ctx.getResponse().setContentType("application/json; charset=utf-8");
            throw new ZuulException(e,"sentinel流控",429,"SentinelZuulPreFilter");


How to reproduce it (as minimally and precisely as possible)

  1. 接入ahas(我接入的公网试用版本)
  2. 在ahas网关防护中添加流控规则
  3. 触发流控

Tell us your environment

spring-cloud-zuul-starter-ahas-sentinel 1.2.2 spring-cloud-starter-netflix-zuul 2.2.6.RELEASE

Anything else we need to know?

stickgoal avatar Nov 20 '20 08:11 stickgoal

We prefer to implement the BlockException handling mechanism by introducing a configurable Handler similar to sentinel-spring-webmvc-adapter, which defaults to returning a fallback response instead of propagating exceptions.

LearningGp avatar Oct 16 '25 02:10 LearningGp