Skip to content

NPE when update Gateway Flow Rule before the api has been requested once #1724

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

Closed
dani3lWong opened this issue Sep 10, 2020 · 2 comments · Fixed by #1729
Closed

NPE when update Gateway Flow Rule before the api has been requested once #1724

dani3lWong opened this issue Sep 10, 2020 · 2 comments · Fixed by #1729
Labels
area/gateway-flow-control Issues or PRs related to API gateway flow control good first issue Good for newcomers kind/bug Category issues or prs related to bug.
Milestone

Comments

@dani3lWong
Copy link
Contributor

dani3lWong commented Sep 10, 2020

Issue Description

Type: bug report

Describe what happened (or what feature you want)

When my program update the rule whith :
GatewayRuleManager.loadRules(new HashSet<>(FLOW_RULES.values()));

if there has one or more Api has not been requested ,
then there the api resource has not related metric.
that will throws a NPE:

java.lang.NullPointerException: null
	at com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayRuleManager$GatewayRulePropertyListener.applyToConvertedParamMap(GatewayRuleManager.java:230) ~[sentinel-api-gateway-adapter-common-1.8.0.jar:na]
	at com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayRuleManager$GatewayRulePropertyListener.applyGatewayRuleInternal(GatewayRuleManager.java:200) ~[sentinel-api-gateway-adapter-common-1.8.0.jar:na]
	at com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayRuleManager$GatewayRulePropertyListener.configUpdate(GatewayRuleManager.java:118) ~[sentinel-api-gateway-adapter-common-1.8.0.jar:na]
	at com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayRuleManager$GatewayRulePropertyListener.configUpdate(GatewayRuleManager.java:114) ~[sentinel-api-gateway-adapter-common-1.8.0.jar:na]
	at com.alibaba.csp.sentinel.property.DynamicSentinelProperty.updateValue(DynamicSentinelProperty.java:57) ~[sentinel-core-1.8.0.jar:1.8.0]
	at com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayRuleManager.loadRules(GatewayRuleManager.java:78) ~[sentinel-api-gateway-adapter-common-1.8.0.jar:na]
	at ****.java:50) ~[classes/:na]
	at ****.java:102) ~[classes/:na]
	at ****.java:52) ~[classes/:na]
	at sun.reflect.GeneratedMethodAccessor81.invoke(Unknown Source) ~[na:na]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_201]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_201]
	at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:84) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:93) [spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_201]
	at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266) [na:1.8.0_201]
	at java.util.concurrent.FutureTask.run(FutureTask.java) [na:1.8.0_201]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_201]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [na:1.8.0_201]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_201]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_201]
	at java.lang.Thread.run(Thread.java:748) [na:1.8.0_201]

Because there has not metric for this resource , but the method:

com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayRuleManager.GatewayRulePropertyListener private void applyToConvertedParamMap(@NotNull Set<ParamFlowRule> paramFlowRules)

try to clear that with :

ParameterMetricStorage.getParamMetricForResource(resource).clearForRule(rule);

in com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayRuleManager.GatewayRulePropertyListener
(233 line in com/alibaba/csp/sentinel/adapter/gateway/common/rule/GatewayRuleManager.java)

Describe what you expected to happen

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

  1. init a api resource with gateway rule manager
  2. update that before that has been requested

Tell us your environment

Sentinel Version : 1.8

Anything else we need to know?

@sczyh30 sczyh30 added area/gateway-flow-control Issues or PRs related to API gateway flow control good first issue Good for newcomers kind/bug Category issues or prs related to bug. labels Sep 11, 2020
@sczyh30
Copy link
Member

sczyh30 commented Sep 11, 2020

Thanks for reporting. That's a bug. Would you like to submit a PR to fix it?

@sczyh30 sczyh30 added this to the 1.8.1 milestone Sep 11, 2020
dani3lWong added a commit to dani3lWong/Sentinel that referenced this issue Sep 11, 2020
@sczyh30 sczyh30 linked a pull request Sep 11, 2020 that will close this issue
dani3lWong added a commit to dani3lWong/Sentinel that referenced this issue Sep 11, 2020
dani3lWong added a commit to dani3lWong/Sentinel that referenced this issue Sep 11, 2020
dani3lWong added a commit to dani3lWong/Sentinel that referenced this issue Sep 11, 2020
@sczyh30 sczyh30 removed a link to a pull request Sep 14, 2020
@zhangxiangfeng
Copy link

zhangxiangfeng commented Jan 18, 2021

我修复了一下,打了一个包,测试过没问题。

链接: https://pan.baidu.com/s/1gGT1bUhePzjvvhEMyvjVCQ 提取码: mkxr 复制这段内容后打开百度网盘手机App,操作更方便哦

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/gateway-flow-control Issues or PRs related to API gateway flow control good first issue Good for newcomers kind/bug Category issues or prs related to bug.
Projects
None yet
3 participants