shenyu icon indicating copy to clipboard operation
shenyu copied to clipboard

[BUG] DataPermissionServiceImpl.createSelector is not transactional

Open Aias00 opened this issue 4 months ago • 2 comments

Description

createSelector inserts the SELECTOR permission row, then collects all rules for that selector and inserts RULE permission rows in a single insertBatch. The method has no @Transactional. If the batch insert throws (duplicate key, constraint, DB error), the selector permission row remains committed. The sibling methods createRule (line 227) and deleteSelector (line 139) are both @Transactional(rollbackFor = Exception.class).

Location

shenyu-admin/.../service/impl/DataPermissionServiceImpl.java:111-129
createRule at :227, deleteSelector at :139

Impact

Orphan selector permission with no/partial rule permissions; a user appears to have selector access but no rule access.

Suggested fix

Add @Transactional(rollbackFor = Exception.class) to createSelector.

Related existing issue(s)

None

Identified during the 2026-08-02 audit; full list in docs/issue-candidates-2026-08-02.md.

Aias00 avatar Aug 02 '26 12:08 Aias00

👋 Hello @yuluo-yx

A new issue has been opened by @Aias00:

  • Title: [BUG] DataPermissionServiceImpl.createSelector is not transactional
  • Link: https://github.com/apache/shenyu/issues/6549

Please review when you have time. Thank you! 🙏

github-actions[bot] avatar Aug 02 '26 12:08 github-actions[bot]

I rechecked this against current upstream/master (09c6a5287330c8d6ada64cd29f2a08a570b0b2ab) and the reported two-write sequence does not match the implementation.

createSelector builds allDOList in memory, adds the selector row and any rule rows, then invokes dataPermissionMapper.insertBatch(allDOList) exactly once. The mapper maps that call to one multi-row INSERT statement (default dialect; Oracle uses one INSERT ... SELECT ... UNION ALL statement at lines 181–189).

So this path does not commit a selector permission in one call and then insert rule permissions in a second call; a failure of the single insert statement cannot leave behind only the selector row as described. Adding @Transactional may be harmless, but it does not appear to fix the stated failure mode. If there is a current reproduction showing partial rows after the single mapper statement fails, please share the database/engine and steps; otherwise this issue may be outdated or based on a mistaken read of the method.

sunnysabor avatar Oct 01 '26 22:10 sunnysabor