apache / shenyu

Apache ShenYu is a Java native API Gateway for service proxy, protocol conversion and API governance.
https://shenyu.apache.org/
Apache License 2.0
8.43k stars 2.93k forks source link

[BUG] why thre are two same selector when register a new client #5550

Open zlp1992 opened 5 months ago

zlp1992 commented 5 months ago

Bug

when i register a new client,there are two same selector data image and in database, there are two records image after debug, i find if using nacos as registration center, and deploy more than one admin instance(for example two). when i start a client and to register, both admin server receive nacos change event and start to register meta data as follow: org.apache.shenyu.admin.service.impl.SelectorServiceImpl#registerDefault(org.apache.shenyu.register.common.dto.MetaDataRegisterDTO, java.lang.String, java.lang.String) below code, both admin instance with not find selectorDO and will create two same selector data

String contextPath = ContextPathUtils.buildContextPath(dto.getContextPath(), dto.getAppName());
        SelectorDO selectorDO = findByNameAndPluginName(contextPath, pluginName);
        if (Objects.isNull(selectorDO)) {
            SelectorDTO selectorDTO = SelectorUtil.buildSelectorDTO(contextPath, pluginMapper.selectByName(pluginName).getId());
            selectorDTO.setHandle(selectorHandler);
            return registerDefault(selectorDTO);
        }

that cause lot of warn AbstractRetryTask [shenyu-shared_wheel_timer-2] Failed to execute task:/o:divide,retried:1 ,total retries:-1,cause:nested exception is org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 2

Aias00 commented 5 months ago

version pls?

zlp1992 commented 5 months ago

version pls?

2.5.0,a little bit old, but i see the newest code org.apache.shenyu.admin.service.register.AbstractShenyuClientRegisterServiceImpl#register may has the same problem if more than one shenyu admin instance receive meta data register nacos change event at the same time

Aias00 commented 5 months ago

version pls?

2.5.0,a little bit old, but i see the newest code org.apache.shenyu.admin.service.register.AbstractShenyuClientRegisterServiceImpl#register may has the same problem if more than one shenyu admin instance receive meta data register nacos change event at the same time

hi, if u have time to handle this problem, u can make a pr to resolve it. 😊