[BUG] Publish-before-commit: PROXY_SELECTOR CREATE event dispatched inside @Transactional registerDiscoveryConfig before commit
- Dominant language
- Java
- Stars
- 8.8k
- Forks
- 3.1k
- Avg merge
- 7d 1h
- Merged PRs (30d)
- 85
Description
- severity: Medium-High
- files: `shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DiscoveryServiceImpl.java:121-125,185-188`; `shenyu-admin/src/main/java/org/apache/shenyu/admin/discovery/DefaultDiscoveryProcessor.java:82-84`; `shenyu-admin/src/main/java/org/apache/shenyu/admin/listener/DataChangedEventDispatcher.java`
- description: `registerDiscoveryConfig` is `@Transactional(rollbackFor=Exception.class)`. Inside it `bindingDiscovery` inserts `discovery`/`discoveryHandler`/`discoveryRel` rows and then calls `discoveryProcessor.createProxySelector(...)`, which publishes `DataChangedEvent(PROXY_SELECTOR, CREATE)`. `DataChangedEventDispatcher` implements `ApplicationListener` (a synchronous Spring listener, NOT `@TransactionalEventListener(AFTER_COMMIT)`), so the gateway-sync listeners push the new proxySelector to the gateway BEFORE the transaction commits. The same method also calls `createDiscovery` (network registry init + watch registration) as an un-rollbackable side effect inside the tx. If the tx rolls back, the gateway has received a CREATE for a proxySelector whose DB rows were rolled back, and the registry connection/watch is leaked.
- impact: Ghost proxySelector in gateway / divergent admin-vs-gateway state on rollback of discovery binding; leaked registry watch resources.
- suggested_fix: Move the `createDiscovery`/`createProxySelector` (and the event publish) to an after-commit phase (`@TransactionalEventListener(phase=AFTER_COMMIT)`).
- confidence: Medium-High
- related_existing: none. #6479 is about delete stale cache; this is a CREATE publish-before-commit (transaction visibility) defect.
---
_Identified during the 2026-08-02 deep re-scan; full list in [`docs/scan2-2026-08-02/06-medium-tiers.md`](docs/scan2-2026-08-02/06-medium-tiers.md)._
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the listed ranges in DiscoveryServiceImpl.java, then trace createProxySelector in DefaultDiscoveryProcessor.java and event handling in DataChangedEventDispatcher.java. Verify how rollback affects the database, gateway event, and registry watch, and add or update coverage so CREATE side effects occur only after a successful commit without leaking resources on rollback.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- backend, distributed-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100