apache/shenyu · error · ShenyuException

shared thread pool is not enable, config

Error message

shared thread pool is not enable, config ${shenyu.sharedPool.enable} in your xml/yml !

What it means

ApplicationConfigCache.initThreadPool for the SOFA plugin resolves the executor for sofa RPC calls. With threadpool=shared it looks up the ShenyuThreadPoolExecutor bean and throws ShenyuException if the bean is missing because shared pool support was not enabled; fixed/eager/limited throw UnsupportedOperationException outright.

Solutions

  1. Set shenyu.sharedPool.enable: true in the gateway's application.yml.
  2. Or change the sofa threadpool config to 'cached' (supported default).
  3. Confirm the dependency/starter that registers ShenyuThreadPoolExecutor is present in the bootstrap pom.
  4. Restart the gateway so init() runs with the corrected configuration.

Example fix

// before
shenyu:
  sofa:
    threadpool: shared
// after
shenyu:
  sharedPool:
    enable: true
  sofa:
    threadpool: shared
Defensive patterns

Strategy: validation

Validate before calling

if ("shared".equals(config.getThreadpool())
        && SpringBeanUtils.getInstance().getApplicationContext()
            .getBeansOfType(ShenyuThreadPoolExecutor.class).isEmpty()) {
    throw new IllegalStateException("sofa shared threadpool requires shenyu.sharedPool.enable=true");
}

Try / catch

try {
    applicationConfigCache.init(sofaConfig);
} catch (ShenyuException e) {
    LOG.error("sofa init failed: {}", e.getMessage());
}

Prevention

When it happens

Trigger: sofa plugin config sets threadpool=shared while shenyu.sharedPool.enable is false/absent; initThreadPool runs during ApplicationConfigCache.init when the sofa plugin loads configuration.

Common situations: Sofa plugin enabled with default/example config referencing 'shared'; application.yml missing shenyu.sharedPool.enable; the shared pool starter not included in bootstrap dependencies.

Understand the failure class

Background: "X is required", "must be set", "cannot be empty": the missing-required-config error family, from Vertex AI project/location to WeChat keys — this error's family across 18 libraries.

Related errors


AI-assisted analysis of apache/shenyu@567142e072 (2026-09-12). Data as JSON: /api/errors/1be4f16a5f6b0537. Report an issue: GitHub.

Appendix: source

Thrown at shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-sofa/src/main/java/org/apache/shenyu/plugin/sofa/cache/ApplicationConfigCache.java:166

        Field field = ReflectionUtils.findField(AsyncRuntime.class, "asyncThreadPool");
        ReflectionUtils.makeAccessible(field);
        ReflectionUtils.setField(field, AsyncRuntime.class, threadPool);
    }
    
    /**
     * Init thread pool.
     */
    private void initThreadPool(final SofaRegisterConfig config) {
        if (Objects.nonNull(threadPool)) {
            return;
        }
        switch (config.getThreadpool()) {
            case Constants.SHARED:
                try {
                    threadPool = SpringBeanUtils.getInstance().getBean(ShenyuThreadPoolExecutor.class);
                    return;
                } catch (NoSuchBeanDefinitionException t) {
                    throw new ShenyuException("shared thread pool is not enable, config ${shenyu.sharedPool.enable} in your xml/yml !", t);
                }
            case Constants.FIXED:
            case Constants.EAGER:
            case Constants.LIMITED:
                throw new UnsupportedOperationException();
            case Constants.CACHED:
                int corePoolSize = Optional.ofNullable(config.getCorethreads()).orElse(0);
                int maximumPoolSize = Optional.ofNullable(config.getThreads()).orElse(Integer.MAX_VALUE);
                int queueSize = Optional.ofNullable(config.getQueues()).orElse(0);
                threadPool = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, 60L, TimeUnit.SECONDS,
                        queueSize > 0 ? new LinkedBlockingQueue<>(queueSize) : new SynchronousQueue<>(), factory);
                return;
            default:
        }
    }
    
    /**
     * Init ref reference config.

View on GitHub (pinned to 567142e072)