apache/shenyu · error · ShenyuAdminException

before start ProxySelector you need init DiscoveryId=

Error message

before start ProxySelector you need init DiscoveryId=%s

What it means

DefaultDiscoveryProcessor.createProxySelector throws this ShenyuAdminException when the ShenyuInstanceRegisterRepository looked up by discoveryId is null — the discovery instance was never initialized — so a proxy selector cannot be attached to it.

Solutions

  1. Initialize the discovery (create discovery + discovery handler) before creating the proxy selector
  2. Correct the discoveryId to reference an existing, initialized discovery
  3. Re-import/apply config in dependency order: discovery -> discovery handler -> proxy selector

Example fix

// before
defaultProcessor.createProxySelector(handlerDTO, selectorDTO); // repo null for discoveryId
// after
defaultProcessor.createDiscovery(discoveryDTO);
defaultProcessor.createDiscoveryHandler(handlerDTO);
defaultProcessor.createProxySelector(handlerDTO, selectorDTO);
Defensive patterns

Strategy: validation

Validate before calling

if (processor.getShenyuDiscoveryService(discoveryHandlerDTO.getDiscoveryId()) == null) {
    throw new IllegalStateException("discovery not initialized for id " + discoveryHandlerDTO.getDiscoveryId());
}

Try / catch

try {
    processor.createProxySelector(handlerDTO, selectorDTO);
} catch (ShenyuAdminException e) {
    if (e.getMessage().contains("you need init DiscoveryId")) { /* init discovery then retry */ }
}

Prevention

When it happens

Trigger: createProxySelector invoked with discoveryHandlerDTO.getDiscoveryId() that has no initialized discovery repository in the processor's state; same root cause as the AP processor variant but on the default processor path.

Common situations: Out-of-order config creation/import (selector before discovery); dashboard calls bypassing the discovery creation step; discoveryId typo or stale reference after discovery deletion.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


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

Appendix: source

Thrown at shenyu-admin/src/main/java/org/apache/shenyu/admin/discovery/DefaultDiscoveryProcessor.java:56

 * DefaultDiscoveryProcessor.
 */
public class DefaultDiscoveryProcessor extends AbstractDiscoveryProcessor {

    /**
     * DefaultDiscoveryProcessor.
     *
     * @param discoveryUpstreamMapper discoveryUpstreamMapper
     */
    public DefaultDiscoveryProcessor(final DiscoveryUpstreamMapper discoveryUpstreamMapper) {
        super(discoveryUpstreamMapper);
    }

    @Override
    public void createProxySelector(final DiscoveryHandlerDTO discoveryHandlerDTO, final ProxySelectorDTO proxySelectorDTO) {
        ShenyuInstanceRegisterRepository shenyuInstanceRegisterRepository = getShenyuDiscoveryService(discoveryHandlerDTO.getDiscoveryId());
        String key = buildProxySelectorKey(discoveryHandlerDTO.getListenerNode());
        if (Objects.isNull(shenyuInstanceRegisterRepository)) {
            throw new ShenyuAdminException(String.format("before start ProxySelector you need init DiscoveryId=%s", discoveryHandlerDTO.getDiscoveryId()));
        }

        if (!shenyuInstanceRegisterRepository.serviceExists(key)) {
            throw new ShenyuAdminException(String.format("shenyu discovery start watcher need you has this key %s in Discovery", key));
        }
        Set<String> cacheKey = getCacheKey(discoveryHandlerDTO.getDiscoveryId());
        if (Objects.nonNull(cacheKey) && cacheKey.contains(key)) {
            LOG.info("shenyu discovery has watcher key = {}", key);
            super.addDiscoverySyncDataListener(discoveryHandlerDTO, proxySelectorDTO);
            return;
        }
        final DataChangedEventListener discoveryDataChangedEventListener = getDiscoveryDataChangedEventListener(discoveryHandlerDTO, proxySelectorDTO);
        shenyuInstanceRegisterRepository.watchInstances(key, (selectKey, selectValue, event) -> {
            if (event.equals(ChangedEventListener.Event.ADDED)) {
                discoveryDataChangedEventListener.onChange(new DiscoveryDataChangedEvent(selectKey, selectValue, DiscoveryDataChangedEvent.Event.ADDED));
            } else if (event.equals(ChangedEventListener.Event.UPDATED)) {
                discoveryDataChangedEventListener.onChange(new DiscoveryDataChangedEvent(selectKey, selectValue, DiscoveryDataChangedEvent.Event.UPDATED));
            } else if (event.equals(ChangedEventListener.Event.DELETED)) {

View on GitHub (pinned to 567142e072)