{"record":{"id":"d376f7a3b119eb55","repo":"apache/shenyu","slug":"before-start-proxyselector-you-need-init-discoveryid-s-d376f7","errorCode":null,"errorMessage":"before start ProxySelector you need init DiscoveryId=%s","messagePattern":"before start ProxySelector you need init DiscoveryId=(.+?)","errorType":"exception","errorClass":"ShenyuAdminException","httpStatus":null,"severity":"error","filePath":"shenyu-admin/src/main/java/org/apache/shenyu/admin/discovery/DefaultDiscoveryProcessor.java","lineNumber":56,"sourceCode":" * DefaultDiscoveryProcessor.\n */\npublic class DefaultDiscoveryProcessor extends AbstractDiscoveryProcessor {\n\n    /**\n     * DefaultDiscoveryProcessor.\n     *\n     * @param discoveryUpstreamMapper discoveryUpstreamMapper\n     */\n    public DefaultDiscoveryProcessor(final DiscoveryUpstreamMapper discoveryUpstreamMapper) {\n        super(discoveryUpstreamMapper);\n    }\n\n    @Override\n    public void createProxySelector(final DiscoveryHandlerDTO discoveryHandlerDTO, final ProxySelectorDTO proxySelectorDTO) {\n        ShenyuInstanceRegisterRepository shenyuInstanceRegisterRepository = getShenyuDiscoveryService(discoveryHandlerDTO.getDiscoveryId());\n        String key = buildProxySelectorKey(discoveryHandlerDTO.getListenerNode());\n        if (Objects.isNull(shenyuInstanceRegisterRepository)) {\n            throw new ShenyuAdminException(String.format(\"before start ProxySelector you need init DiscoveryId=%s\", discoveryHandlerDTO.getDiscoveryId()));\n        }\n\n        if (!shenyuInstanceRegisterRepository.serviceExists(key)) {\n            throw new ShenyuAdminException(String.format(\"shenyu discovery start watcher need you has this key %s in Discovery\", key));\n        }\n        Set<String> cacheKey = getCacheKey(discoveryHandlerDTO.getDiscoveryId());\n        if (Objects.nonNull(cacheKey) && cacheKey.contains(key)) {\n            LOG.info(\"shenyu discovery has watcher key = {}\", key);\n            super.addDiscoverySyncDataListener(discoveryHandlerDTO, proxySelectorDTO);\n            return;\n        }\n        final DataChangedEventListener discoveryDataChangedEventListener = getDiscoveryDataChangedEventListener(discoveryHandlerDTO, proxySelectorDTO);\n        shenyuInstanceRegisterRepository.watchInstances(key, (selectKey, selectValue, event) -> {\n            if (event.equals(ChangedEventListener.Event.ADDED)) {\n                discoveryDataChangedEventListener.onChange(new DiscoveryDataChangedEvent(selectKey, selectValue, DiscoveryDataChangedEvent.Event.ADDED));\n            } else if (event.equals(ChangedEventListener.Event.UPDATED)) {\n                discoveryDataChangedEventListener.onChange(new DiscoveryDataChangedEvent(selectKey, selectValue, DiscoveryDataChangedEvent.Event.UPDATED));\n            } else if (event.equals(ChangedEventListener.Event.DELETED)) {","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/apache/shenyu/blob/567142e07261b3e615ae8850b30f4421f455cc5d/shenyu-admin/src/main/java/org/apache/shenyu/admin/discovery/DefaultDiscoveryProcessor.java#L38-L74","documentation":"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.","triggerScenarios":"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.","commonSituations":"Out-of-order config creation/import (selector before discovery); dashboard calls bypassing the discovery creation step; discoveryId typo or stale reference after discovery deletion.","solutions":["Initialize the discovery (create discovery + discovery handler) before creating the proxy selector","Correct the discoveryId to reference an existing, initialized discovery","Re-import/apply config in dependency order: discovery -> discovery handler -> proxy selector"],"exampleFix":"// before\ndefaultProcessor.createProxySelector(handlerDTO, selectorDTO); // repo null for discoveryId\n// after\ndefaultProcessor.createDiscovery(discoveryDTO);\ndefaultProcessor.createDiscoveryHandler(handlerDTO);\ndefaultProcessor.createProxySelector(handlerDTO, selectorDTO);","handlingStrategy":"validation","validationCode":"if (processor.getShenyuDiscoveryService(discoveryHandlerDTO.getDiscoveryId()) == null) {\n    throw new IllegalStateException(\"discovery not initialized for id \" + discoveryHandlerDTO.getDiscoveryId());\n}","typeGuard":null,"tryCatchPattern":"try {\n    processor.createProxySelector(handlerDTO, selectorDTO);\n} catch (ShenyuAdminException e) {\n    if (e.getMessage().contains(\"you need init DiscoveryId\")) { /* init discovery then retry */ }\n}","preventionTips":["Ensure discovery creation calls complete before selector creation in automation","Use ids returned by the discovery creation API, not hand-written values","Order config imports: discovery, discovery handler, proxy selector"],"tags":["discovery","proxy-selector","initialization-order"],"backgroundTag":"invalid-state-transition","analyzedSha":"567142e07261b3e615ae8850b30f4421f455cc5d","analyzedAt":"2026-09-12T10:08:21.293Z","contentChangedAt":"2026-09-12T10:08:21.293Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}