Aias00 opened a new issue, #7733: URL: https://github.com/apache/shenyu/issues/7733
## Current behavior `InstanceInfoServiceImpl.createOrUpdate` performs `selectOneByQuery` and then inserts an entity with a new random primary key when absent. The instance table has a primary key on id but no unique constraint for the queried logical identity `(namespace_id, instance_ip, instance_port, instance_type)`. If two writers observe the same absent identity before either insert completes, both insert different ids successfully. Subsequent `selectOneByQuery` uses `LIMIT 1` without selecting a canonical duplicate, so persistence can update only one row while list/count/history retain both. This race requires overlapping writers (for example concurrent service invocations or multiple standalone Admin writers sharing a database). It is not asserted to occur in the normal single-master, single-scheduler path. A database concurrency reproduction is required. ## Source evidence - [Check-then-insert](https://github.com/apache/shenyu/blob/66d7d954ca37d651a5ad916f988a8081157a7ab4/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/InstanceInfoServiceImpl.java#L53) - [Identity lookup and insert](https://github.com/apache/shenyu/blob/66d7d954ca37d651a5ad916f988a8081157a7ab4/shenyu-admin/src/main/resources/mappers/instance-info-sqlmap.xml#L111) - [Random primary key creation](https://github.com/apache/shenyu/blob/66d7d954ca37d651a5ad916f988a8081157a7ab4/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/InstanceInfoDO.java#L272) - [MySQL table constraints](https://github.com/apache/shenyu/blob/66d7d954ca37d651a5ad916f988a8081157a7ab4/db/init/mysql/schema.sql#L2371); equivalent reviewed Oracle/H2/PostgreSQL schemas likewise lack identity uniqueness. ## Acceptance criteria - [ ] Define canonical instance identity and enforce it at the database boundary, using a dialect-compatible atomic upsert or duplicate-conflict recovery; a JVM lock alone does not cover separate Admin processes. - [ ] Provide a safe deterministic cleanup/migration policy for existing duplicates before adding a unique constraint. - [ ] A barrier-controlled database integration test makes two writers observe absence and verifies one logical row remains; test repeated updates and namespace separation. - [ ] Preserve the most recent valid observation on conflict; do not silently swallow duplicate errors and lose a newer report. - [ ] Validate key lengths/index limits and migration on supported dialects, including Oracle compatibility work #7724. Related: #7717 tracks retention, #7697 status-query authority and #7723 heartbeat persistence. Those fixes do not enforce identity uniqueness. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
