alibaba/Sentinel · error · ContextNameDefineException

The sentinel_default_context can't be permit to defined!

Error message

The sentinel_default_context can't be permit to defined!

What it means

ContextUtil.enter(name, origin) explicitly forbids using Sentinel's reserved default context name 'sentinel_default_context' as a custom context: doing so throws ContextNameDefineException. The default context is created internally by ContextUtil.internalEnter for users who never call enter(); letting callers register it manually would collide with that internal bookkeeping.

Source

Thrown at sentinel-core/src/main/java/com/alibaba/csp/sentinel/context/ContextUtil.java:114

     * The origin node will be created in {@link com.alibaba.csp.sentinel.slots.clusterbuilder.ClusterBuilderSlot}.
     * Note that each distinct {@code origin} of different resources will lead to creating different new
     * {@link Node}, meaning that total amount of created origin statistic nodes will be:<br/>
     * {@code distinct resource name amount * distinct origin count}.<br/>
     * So when there are too many origins, memory footprint should be carefully considered.
     * </p>
     * <p>
     * Same resource in different context will count separately, see {@link NodeSelectorSlot}.
     * </p>
     *
     * @param name   the context name
     * @param origin the origin of this invocation, usually the origin could be the Service
     *               Consumer's app name. The origin is useful when we want to control different
     *               invoker/consumer separately.
     * @return The invocation context of the current thread
     */
    public static Context enter(String name, String origin) {
        if (Constants.CONTEXT_DEFAULT_NAME.equals(name)) {
            throw new ContextNameDefineException(
                "The " + Constants.CONTEXT_DEFAULT_NAME + " can't be permit to defined!");
        }
        return trueEnter(name, origin);
    }

    protected static Context trueEnter(String name, String origin) {
        Context context = contextHolder.get();
        if (context == null) {
            Map<String, DefaultNode> localCacheNameMap = contextNameNodeMap;
            DefaultNode node = localCacheNameMap.get(name);
            if (node == null) {
                if (localCacheNameMap.size() > Constants.MAX_CONTEXT_NAME_SIZE) {
                    setNullContext();
                    return NULL_CONTEXT;
                } else {
                    LOCK.lock();
                    try {
                        node = contextNameNodeMap.get(name);

View on GitHub (pinned to a3f40ba8e9)

Solutions

  1. Use a distinct, meaningful context name, e.g. ContextUtil.enter("myServiceContext", origin)
  2. If the context name comes from external input, blacklist Constants.CONTEXT_DEFAULT_NAME before calling enter
  3. If you actually want the default behavior, simply omit ContextUtil.enter — Sentinel uses the default context automatically

Example fix

// before
ContextUtil.enter("sentinel_default_context", "consumerA");

// after
ContextUtil.enter("orderServiceContext", "consumerA");
Defensive patterns

Strategy: validation

Validate before calling

String safeName = Constants.CONTEXT_DEFAULT_NAME.equals(name) ? "appContext" : name;
ContextUtil.enter(safeName, origin);

Prevention

When it happens

Trigger: Calling ContextUtil.enter("sentinel_default_context", origin) or Constants.CONTEXT_DEFAULT_NAME directly; deriving context names from config/user input that happens to equal the reserved constant.

Common situations: Hardcoding a context name without knowing the reserved value; echoing the name seen in Sentinel dashboard/log (which shows sentinel_default_context when no context is set) back into enter(); property-driven context naming in multi-tenant gateways.

Related errors


AI-assisted analysis of alibaba/Sentinel@a3f40ba8e9 (2026-08-14). Data as JSON: /api/errors/32f3d0cbd7f8ad96. Report an issue: GitHub.