apache / apache/shenyu

[BUG] Publish-before-commit: DISCOVER_UPSTREAM UPDATE published inside @Transactional updateBatch before delete+reinsert commits

Open
#6,685 1 comment 0 reactions 0 assignees View on GitHub
admin priority: medium type: bug
Dominant language
Java
Stars
8.8k
Forks
3.1k
Avg merge
7d 1h
Merged PRs (30d)
85

Description

- severity: Medium
- files: `shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DiscoveryUpstreamServiceImpl.java:109-120,333-352`; `shenyu-admin/src/main/java/org/apache/shenyu/admin/discovery/AbstractDiscoveryProcessor.java:154-164`
- description: `updateBatch` is `@Transactional`. It does `deleteByDiscoveryHandlerId` then re-inserts each upstream, then calls `this.fetchAll(discoveryHandlerId)` at line 118 while still inside the uncommitted transaction. `fetchAll` reads the upstreams (visible only within this tx), builds a `DiscoverySyncData` and calls `discoveryProcessor.changeUpstream`, which publishes `DataChangedEvent(DISCOVER_UPSTREAM, UPDATE)`. The synchronous dispatcher pushes that upstream list to the gateway before the tx commits. If the tx rolls back, the gateway holds an upstream list that no longer exists in DB.
- impact: Stale/wrong upstream view pushed to gateway on rollback of batch upstream replacement; gateway may route to upstreams that were rolled back.
- suggested_fix: Move the `fetchAll`/`changeUpstream` publish to an `AFTER_COMMIT` phase.
- confidence: Medium-High
- related_existing: none. Not #6479 (delete stale); this is publish-before-commit on the update/batch path.

---
_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 in DiscoveryUpstreamServiceImpl.java at lines 109-120 and 333-352, then read AbstractDiscoveryProcessor.java lines 154-164 to trace updateBatch, fetchAll, and changeUpstream. Verify the publish path against transaction commit and rollback behavior. Done means DISCOVER_UPSTREAM UPDATE is delivered only after a successful commit, with no update published when the transaction rolls back.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.