This is an automated email from the ASF dual-hosted git repository.

liuhongyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git


The following commit(s) were added to refs/heads/master by this push:
     new 2627a12519 [fix] fix config import (#6051)
2627a12519 is described below

commit 2627a1251917ac4324cfadef397506509d2f0944
Author: richie <[email protected]>
AuthorDate: Sat Jul 19 20:19:15 2025 +0800

    [fix] fix config import (#6051)
    
    * Update ConfigsExportImportController.java
    
    
      🐛 Bug Fix - Commit Message
    
      fix: resolve namespace isolation issue in rule import functionality
    
      The rule import process was incorrectly triggering REFRESH events for all 
namespaces
      instead of only the target namespace, causing cross-namespace event 
pollution.
    
      **Problem:**
      - When importing rules to namespace A, all namespaces (A, B, C...) 
received REFRESH events
      - This was caused by using `syncAll()` which broadcasts to all namespaces
      - Violated namespace isolation principle
    
      **Solution:**
      - Replace `syncAll()` with `syncAllByNamespaceId()` in import controller
      - Ensure only the target namespace receives REFRESH events
      - Maintain proper namespace isolation during rule import operations
    
      **Files Changed:**
      - 
shenyu-admin/src/main/java/com/woo/shenyu/admin/controller/ConfigsExportImportController.java
    
      **Testing:**
      - ✅ Import rules to namespace A - only namespace A receives events
      - ✅ Other namespaces (B, C) are unaffected
      - ✅ Namespace isolation is maintained
    
      📋 GitHub Issue Description
    
      # Bug Report: Cross-Namespace Event Pollution During Rule Import
    
      ## 🐛 **Bug Description**
      When importing rules to a specific namespace, the system incorrectly 
triggers REFRESH events for rules in ALL namespaces instead of only the target 
namespace.
    
      ## 🔍 **Root Cause Analysis**
      The issue is in `ConfigsExportImportController.java` line 146:
      ```java
      // Problem: broadcasts to ALL namespaces
      syncDataService.syncAll(DataEventTypeEnum.REFRESH);
    
      The syncAll() method:
      1. Fetches rules from ALL namespaces via ruleService.listAll()
      2. Groups by namespace and sends events to each namespace
      3. Causes namespace B to receive REFRESH events when importing to 
namespace A
    
      🔧 Fix Applied
    
      Replace the problematic call with namespace-specific synchronization:
      // Solution: only sync target namespace
      syncDataService.syncAllByNamespaceId(DataEventTypeEnum.REFRESH, 
namespace);
    
      📊 Impact
    
      - Before: Cross-namespace event pollution
      - After: Proper namespace isolation
      - Affected Component: Rule import functionality
      - Severity: Medium (violates namespace isolation)
    
      ✅ Testing
    
      - Import rules to namespace A - only A receives events
      - Namespace B and C clients remain unaffected
      - WebSocket event filtering works correctly
      - No performance impact on other namespaces
    
      📁 Files Modified
    
      - 
shenyu-admin/src/main/java/com/woo/shenyu/admin/controller/ConfigsExportImportController.java
    
      🏷️ Labels
    
      - bug
      - namespace
      - websocket
      - data-sync
      - isolation
    
      ## 🚀 **Pull Request Title**
      fix: resolve namespace isolation issue in rule import functionality
    
    * update
    
    ---------
    
    Co-authored-by: moremind <[email protected]>
    Co-authored-by: aias00 <[email protected]>
---
 .../apache/shenyu/admin/controller/ConfigsExportImportController.java | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/ConfigsExportImportController.java
 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/ConfigsExportImportController.java
index 752ba5a5bc..1354b09248 100644
--- 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/ConfigsExportImportController.java
+++ 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/ConfigsExportImportController.java
@@ -137,8 +137,8 @@ public class ConfigsExportImportController {
         try {
             ShenyuAdminResult importResult = 
configsService.configsImport(namespace, file.getBytes());
             if (Objects.equals(CommonErrorCode.SUCCESSFUL, 
importResult.getCode())) {
-                // sync data
-                syncDataService.syncAll(DataEventTypeEnum.REFRESH);
+                // sync data only for the target namespace to avoid 
cross-namespace refresh events
+                
syncDataService.syncAllByNamespaceId(DataEventTypeEnum.REFRESH, namespace);
             }
             return importResult;
         } catch (IOException e) {

Reply via email to