apache / apache/shenyu

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

Open
#5,550 3 comments 0 reactions 0 assignees View on GitHub
type: question
Dominant language
Java
Stars
8.8k
Forks
3.1k
Avg merge
7d 1h
Merged PRs (30d)
85

Description

### Bug

when i register a new client,there are two same selector data
![image](https://github.com/apache/shenyu/assets/11548492/482db876-fa90-4844-9f3d-0a9a91e5d3e2)
and in database, there are two records
![image](https://github.com/apache/shenyu/assets/11548492/70c858e6-8ce2-4aed-b5c9-06519a3bd46b)
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`

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at org.apache.shenyu.admin.service.impl.SelectorServiceImpl#registerDefault and trace the Nacos registration event handling when multiple admin instances receive the same change. Reproduce with two admin instances and inspect the selector records created for one client registration. Done means duplicate selectors are prevented and the TooManyResultsException warnings no longer occur.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend, databases, distributed-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.