Fix the bug that context was not released when blocked in Spring Web adapter (#1353)
This commit is contained in:
parent
b715ceacf0
commit
43b5e65ab3
|
|
@ -67,7 +67,11 @@ public abstract class AbstractSentinelInterceptor implements HandlerInterceptor
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} catch (BlockException e) {
|
} catch (BlockException e) {
|
||||||
handleBlockException(request, response, e);
|
try {
|
||||||
|
handleBlockException(request, response, e);
|
||||||
|
} finally {
|
||||||
|
ContextUtil.exit();
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -71,18 +71,21 @@ public class SentinelSpringMvcIntegrationTest {
|
||||||
final String headerName = "S-User";
|
final String headerName = "S-User";
|
||||||
configureRulesFor(springMvcPathVariableUrl, 0, limitOrigin);
|
configureRulesFor(springMvcPathVariableUrl, 0, limitOrigin);
|
||||||
|
|
||||||
|
// This will be passed since the caller is different: userB
|
||||||
this.mvc.perform(get("/foo/1").accept(MediaType.TEXT_PLAIN).header(headerName, "userB"))
|
this.mvc.perform(get("/foo/1").accept(MediaType.TEXT_PLAIN).header(headerName, "userB"))
|
||||||
.andExpect(status().isOk())
|
.andExpect(status().isOk())
|
||||||
.andExpect(content().string("foo 1"));
|
.andExpect(content().string("foo 1"));
|
||||||
|
|
||||||
// This will be blocked and reponse json.
|
// This will be blocked since the caller is same: userA
|
||||||
this.mvc.perform(
|
this.mvc.perform(
|
||||||
get("/foo/2").accept(MediaType.APPLICATION_JSON).header(headerName, limitOrigin))
|
get("/foo/2").accept(MediaType.APPLICATION_JSON).header(headerName, limitOrigin))
|
||||||
.andExpect(status().isOk())
|
.andExpect(status().isOk())
|
||||||
.andExpect(content().json(ResultWrapper.blocked().toJsonString()));
|
.andExpect(content().json(ResultWrapper.blocked().toJsonString()));
|
||||||
|
|
||||||
|
// This will be passed since the caller is different: ""
|
||||||
this.mvc.perform(get("/foo/3").accept(MediaType.APPLICATION_JSON))
|
this.mvc.perform(get("/foo/3").accept(MediaType.APPLICATION_JSON))
|
||||||
.andExpect(status().isOk())
|
.andExpect(status().isOk())
|
||||||
.andExpect(content().string(ResultWrapper.blocked().toJsonString()));
|
.andExpect(content().string("foo 3"));
|
||||||
|
|
||||||
FlowRuleManager.loadRules(null);
|
FlowRuleManager.loadRules(null);
|
||||||
}
|
}
|
||||||
|
|
@ -115,7 +118,7 @@ public class SentinelSpringMvcIntegrationTest {
|
||||||
assertEquals(i + 1, cn.passQps(), 0.01);
|
assertEquals(i + 1, cn.passQps(), 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This will be blocked and reponse json.
|
// This will be blocked and response json.
|
||||||
this.mvc.perform(get(url))
|
this.mvc.perform(get(url))
|
||||||
.andExpect(status().isOk())
|
.andExpect(status().isOk())
|
||||||
.andExpect(content().string(ResultWrapper.blocked().toJsonString()));
|
.andExpect(content().string(ResultWrapper.blocked().toJsonString()));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue