Closed
Description
Issue Description
Type: bug report (essential)
Describe what happened
When context count exceeds MAX_CONTEXT_NAME_SIZE
(by now 2000), entries with new context will cause fatal internal errors, leading to some weird exceptions (e.g. ErrorEntryFreeException
).
The NullContext
does not act as expected due to bugs in ContextUtil#trueEnter
.
Describe what you expected to happen
When context count exceeds MAX_CONTEXT_NAME_SIZE
, entries with new context should not pass the slot chain. Entries with default context can go through the slot chain.
How to reproduce it (as minimally and precisely as possible)
A test program:
public class Test {
public static void main(String[] args) {
loadContexts();
try {
ContextUtil.enter("context-more");
entryFor("abc");
entryFor("bcd");
} finally {
ContextUtil.exit();
}
}
private static void loadContexts() {
for (int i = 0; i < 2018; i++) {
ContextUtil.enter("a" + i);
ContextUtil.exit();
}
}
private static void entryFor(String resourceName) {
Entry entry = null;
try {
entry = SphU.entry(resourceName);
} catch (BlockException ex) {
ex.printStackTrace();
} finally {
if (entry != null) {
entry.exit();
}
}
}
}
Then errors will be found in associated record.log
like this:
2018-09-18 22:20:01 Sentinel unexpected exception
java.lang.NullPointerException
at com.alibaba.csp.sentinel.slots.nodeselector.NodeSelectorSlot.entry(NodeSelectorSlot.java:166)
at com.alibaba.csp.sentinel.slotchain.AbstractLinkedProcessorSlot.transformEntry(AbstractLinkedProcessorSlot.java:40)
at com.alibaba.csp.sentinel.slotchain.AbstractLinkedProcessorSlot.fireEntry(AbstractLinkedProcessorSlot.java:32)
at com.alibaba.csp.sentinel.slotchain.DefaultProcessorSlotChain$1.entry(DefaultProcessorSlotChain.java:31)
at com.alibaba.csp.sentinel.slotchain.AbstractLinkedProcessorSlot.transformEntry(AbstractLinkedProcessorSlot.java:40)
at com.alibaba.csp.sentinel.slotchain.DefaultProcessorSlotChain.entry(DefaultProcessorSlotChain.java:75)
at com.alibaba.csp.sentinel.CtSph.entry(CtSph.java:142)
at com.alibaba.csp.sentinel.CtSph.entry(CtSph.java:256)
at com.alibaba.csp.sentinel.SphU.entry(SphU.java:86)
at com.alibaba.csp.sentinel.demo.Test.entryFor(Test.java:69)
at com.alibaba.csp.sentinel.demo.Test.main(Test.java:33)
2018-09-18 22:20:01 Entry exit exception
java.lang.NullPointerException
at com.alibaba.csp.sentinel.slots.statistic.StatisticSlot.exit(StatisticSlot.java:115)
at com.alibaba.csp.sentinel.slotchain.AbstractLinkedProcessorSlot.fireExit(AbstractLinkedProcessorSlot.java:46)
at com.alibaba.csp.sentinel.slots.logger.LogSlot.exit(LogSlot.java:49)
at com.alibaba.csp.sentinel.slotchain.AbstractLinkedProcessorSlot.fireExit(AbstractLinkedProcessorSlot.java:46)
at com.alibaba.csp.sentinel.slots.clusterbuilder.ClusterBuilderSlot.exit(ClusterBuilderSlot.java:108)
at com.alibaba.csp.sentinel.slotchain.AbstractLinkedProcessorSlot.fireExit(AbstractLinkedProcessorSlot.java:46)
at com.alibaba.csp.sentinel.slots.nodeselector.NodeSelectorSlot.exit(NodeSelectorSlot.java:176)
at com.alibaba.csp.sentinel.slotchain.AbstractLinkedProcessorSlot.fireExit(AbstractLinkedProcessorSlot.java:46)
at com.alibaba.csp.sentinel.slotchain.DefaultProcessorSlotChain$1.exit(DefaultProcessorSlotChain.java:36)
at com.alibaba.csp.sentinel.slotchain.DefaultProcessorSlotChain.exit(DefaultProcessorSlotChain.java:80)
at com.alibaba.csp.sentinel.CtEntry.exitForContext(CtEntry.java:71)
at com.alibaba.csp.sentinel.CtEntry.trueExit(CtEntry.java:94)
at com.alibaba.csp.sentinel.CtEntry.exit(CtEntry.java:56)
at com.alibaba.csp.sentinel.Entry.exit(Entry.java:74)
at com.alibaba.csp.sentinel.demo.Test.entryFor(Test.java:74)
at com.alibaba.csp.sentinel.demo.Test.main(Test.java:33)
Tell us your environment
- JDK 1.8
- Sentinel 0.2.0-SNAPSHOT (latest in
master
)