apache / apache/shenyu

[BUG] DataPermissionServiceImpl.onSelectorCreate/onRuleCreated event listeners are not transactional and insert per-user in a loop

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

Description

## Description
Both `@EventListener` methods, in the namespace-scoped branch, iterate `namespaceUserRelMapper.selectListByNamespaceId(namespaceId)` and call `dataPermissionMapper.insertSelective(...)` once **per user** with no `@Transactional`. A failure on the Nth insert leaves the first N-1 users granted and the rest not. No dedup against re-delivered events or concurrent creation (duplicates can be inserted).

## Location
```
shenyu-admin/.../service/impl/DataPermissionServiceImpl.java:267 and :305
```

## Impact
Inconsistent data permissions across users in the same namespace — some users see the new selector/rule, others do not, with no rollback.

## Suggested fix
Annotate both listeners `@Transactional(rollbackFor = Exception.class)` and switch to a single batch insert with an idempotency guard (`INSERT ... ON DUPLICATE KEY` or pre-check).

## Related existing issue(s)
None

_Identified during the 2026-08-02 audit; full list in [`docs/issue-candidates-2026-08-02.md`](docs/issue-candidates-2026-08-02.md)._

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in shenyu-admin/.../service/impl/DataPermissionServiceImpl.java at lines 267 and 305, and trace the namespace-scoped listener calls to namespaceUserRelMapper.selectListByNamespaceId and dataPermissionMapper.insertSelective. Verify that a failed insert rolls back all grants and that redelivered or concurrent events do not create duplicates; the work is done when permissions remain consistent for every namespace user.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.