apache / apache/shenyu

[BUG] ScalePolicyServiceImpl.update is non-transactional and triggers scaling side-effect after DB write

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

Description

- severity: High
- files: `shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ScalePolicyServiceImpl.java:80-88`
- description: `update(...)` performs `scalePolicyMapper.updateByPrimaryKeySelective`, then `scalePolicyCache.updatePolicy(...)`, then `scaleService.executeScaling()` with no `@Transactional`. Each mapper call auto-commits immediately. If `executeScaling()` throws after the DB write and cache update have already taken effect, the policy is persisted and cached as the new value but the scaling action was not applied → persistent state drift.
- impact: DB/cache and actual scaling actions can diverge on failure with no rollback; a failed scaling leaves the system in a state where the stored policy says "scaled" but the runtime did not scale (or vice versa).
- suggested_fix: Annotate `update` with `@Transactional(rollbackFor = Exception.class)`; move `scaleService.executeScaling()` to an after-commit phase or call it after the transactional method returns so the side effect only fires on committed state.
- confidence: High
- related_existing: none. N12 is about cache payload shape; this is a transaction-boundary/side-effect-ordering defect in the same method but a distinct concern.

---
_Identified during the 2026-08-02 deep re-scan; full list in [`docs/scan2-2026-08-02/00-consolidated-critical-high.md`](docs/scan2-2026-08-02/00-consolidated-critical-high.md)._

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ScalePolicyServiceImpl.java:80-88 and trace update(...) through the mapper, cache, and scaling calls. Check the transaction boundary and failure behavior, then verify that a failed scaling action cannot leave DB and cache updates committed while the action is unapplied, and that scaling occurs only after a successful commit.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.