{"record":{"id":"61fe824b1ba33d35","repo":"apache/shenyu","slug":"before-start-proxyselector-you-need-init-discoveryid-s","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/APDiscoveryProcessor.java","lineNumber":53,"sourceCode":"import java.util.Set;\n\npublic class APDiscoveryProcessor extends AbstractDiscoveryProcessor {\n\n    /**\n     * DefaultDiscoveryProcessor.\n     *\n     * @param discoveryUpstreamMapper discoveryUpstreamMapper\n     */\n    public APDiscoveryProcessor(final DiscoveryUpstreamMapper discoveryUpstreamMapper) {\n        super(discoveryUpstreamMapper);\n    }\n\n    @Override\n    public void createProxySelector(final DiscoveryHandlerDTO discoveryHandlerDTO, final ProxySelectorDTO proxySelectorDTO) {\n        ShenyuInstanceRegisterRepository shenyuDiscoveryService = getShenyuDiscoveryService(discoveryHandlerDTO.getDiscoveryId());\n        String key = super.buildProxySelectorKey(discoveryHandlerDTO.getListenerNode());\n        if (Objects.isNull(shenyuDiscoveryService)) {\n            throw new ShenyuAdminException(String.format(\"before start ProxySelector you need init DiscoveryId=%s\", discoveryHandlerDTO.getDiscoveryId()));\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        LOG.info(\"shenyu discovery id {} watch key = {}\", discoveryHandlerDTO.getId(), key);\n        final DataChangedEventListener discoveryDataChangedEventListener = getDiscoveryDataChangedEventListener(discoveryHandlerDTO, proxySelectorDTO);\n        shenyuDiscoveryService.watchInstances(key, (selectKey, selectValue, event) -> {\n            LOG.info(\"shenyu discovery receive watch discovery id {} key = {}, value = {}, event = {}\", discoveryHandlerDTO.getId(), 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)) {\n                discoveryDataChangedEventListener.onChange(new DiscoveryDataChangedEvent(selectKey, selectValue, DiscoveryDataChangedEvent.Event.DELETED));\n            } else {","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/apache/shenyu/blob/567142e07261b3e615ae8850b30f4421f455cc5d/shenyu-admin/src/main/java/org/apache/shenyu/admin/discovery/APDiscoveryProcessor.java#L35-L71","documentation":"APDiscoveryProcessor.createProxySelector resolves the ShenyuInstanceRegisterRepository via discoveryHandlerDTO.getDiscoveryId(); when it is null (the discovery handler was never initialized/created first) it throws ShenyuAdminException telling you to init DiscoveryId before starting a ProxySelector. Discovery setup must precede proxy-selector setup.","triggerScenarios":"Calling createProxySelector with a discoveryHandlerDTO whose discoveryId has no matching discovery configuration/processor state — i.e. creating the proxy selector before the discovery config was saved/processed.","commonSituations":"Importing config exports out of order (proxy selectors before discovery configs); API automation creating selectors without the preceding discovery creation call; deleted discovery left referenced by a selector.","solutions":["Create/initialize the Discovery configuration first so its DiscoveryId exists, then create the ProxySelector","If importing, reorder the import so discovery configs are processed before proxy selectors","Verify the discoveryId in the DTO matches an existing discovery record"],"exampleFix":"// before\nprocessor.createProxySelector(discoveryHandlerDTO, proxySelectorDTO); // discoveryId not initialized\n// after\nprocessor.createDiscovery(discoveryDTO);            // init discovery first\nprocessor.createDiscoveryHandler(discoveryHandlerDTO);\nprocessor.createProxySelector(discoveryHandlerDTO, proxySelectorDTO);","handlingStrategy":"validation","validationCode":"if (discoveryServiceRepo.get(discoveryHandlerDTO.getDiscoveryId()) == null) {\n    throw new IllegalStateException(\"initialize Discovery first, discoveryId=\" + discoveryHandlerDTO.getDiscoveryId());\n}","typeGuard":null,"tryCatchPattern":"try {\n    processor.createProxySelector(handlerDTO, selectorDTO);\n} catch (ShenyuAdminException e) {\n    if (e.getMessage().startsWith(\"before start ProxySelector you need init\")) { /* create discovery then retry */ }\n}","preventionTips":["Always create discovery -> discovery handler -> proxy selector in that order","When importing configs, preserve dependency order of discovery entities","Validate discoveryId references before invoking selector APIs"],"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"}