alibaba / alibaba/Sentinel

sentinel exception 无法接收

Open
#2,378 1 comment 0 reactions 0 assignees View on GitHub
area/integrations
Dominant language
Java
Stars
23.1k
Forks
8.1k
PR merge metrics
No merged PRs in 30d

Description

前置条件
sentinel 1.8.1
spring-webmvc-5.2.15

```java
// class name DispatcherServlet

private void processDispatchResult(HttpServletRequest request, HttpServletResponse response,
@Nullable HandlerExecutionChain mappedHandler, @Nullable ModelAndView mv,
@Nullable Exception exception) throws Exception {
boolean errorView = false;
if (exception != null) {
if (exception instanceof ModelAndViewDefiningException) {
logger.debug("ModelAndViewDefiningException encountered", exception);
mv = ((ModelAndViewDefiningException) exception).getModelAndView();
}
else {
Object handler = (mappedHandler != null ? mappedHandler.getHandler() : null);
mv = processHandlerException(request, response, handler, exception);
errorView = (mv != null);
}
}

// Did the handler return a view to render?
if (mv != null && !mv.wasCleared()) {
render(mv, request, response);
if (errorView) {
WebUtils.clearErrorRequestAttributes(request);
}
}
else {
if (logger.isTraceEnabled()) {
logger.trace("No view rendering, null ModelAndView returned.");
}
}
if (WebAsyncUtils.getAsyncManager(request).isConcurrentHandlingStarted()) {
// Concurrent handling started during a forward
return;
}
if (mappedHandler != null) {
// Exception (if any) is already handled..
// 此处的exception并未传递
mappedHandler.triggerAfterCompletion(request, response, null);
}
}

void triggerAfterCompletion(HttpServletRequest request, HttpServletResponse response, @Nullable Exception ex)
throws Exception {

HandlerInterceptor[] interceptors = getInterceptors();
if (!ObjectUtils.isEmpty(interceptors)) {
for (int i = this.interceptorIndex; i >= 0; i--) {
HandlerInterceptor interceptor = interceptors[i];
try {
//此处exception 永远为Null
interceptor.afterCompletion(request, response, this.handler, ex);
}
catch (Throwable ex2) {
logger.error("HandlerInterceptor.afterCompletion threw exception", ex2);
}
}
}
}

//class name AbstractSentinelInterceptor

public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
if (this.increaseReferece(request, this.baseWebMvcConfig.getRequestRefName(), -1) == 0) {
Entry entry = this.getEntryInRequest(request, this.baseWebMvcConfig.getRequestAttributeName());
if (entry == null) {
RecordLog.warn("[{}] No entry found in request, key: {}", new Object[]{this.getClass().getSimpleName(), this.baseWebMvcConfig.getRequestAttributeName()});
} else {
//此处的ex 永远为Null,试问 异常数 和异常比例如何生效
this.traceExceptionAndExit(entry, ex);
this.removeEntryInRequest(request);
ContextUtil.exit();
}
}
}
```

### 类名 DispatcherServlet
### mappedHandler.triggerAfterCompletion(request, response, null); 此处的exception并未传递
### interceptor.afterCompletion(request, response, this.handler, ex); 此处exception 永远为Null
### 类名 AbstractSentinelInterceptor
### this.traceExceptionAndExit(entry, ex); 此处的ex 永远为Null,试问 异常数 和异常比例如何生效

Contributor guide

Open the contributing guide

Research direction

Start with DispatcherServlet.processDispatchResult and HandlerExecutionChain.triggerAfterCompletion, then trace how AbstractSentinelInterceptor.afterCompletion receives the exception. Confirm whether the original exception can reach traceExceptionAndExit so Sentinel's exception count and ratio work correctly; verify the behavior with the relevant Spring MVC integration coverage if available.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.