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

Aias00 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 3e9433d06e fix(sofa): invalidate the bare-path reference on metadata 
removal (#7376)
3e9433d06e is described below

commit 3e9433d06e208106bf6fbc3f6cb829c36fd2478c
Author: Sean-Walker0 <[email protected]>
AuthorDate: Wed Sep 30 10:45:32 2026 +0800

    fix(sofa): invalidate the bare-path reference on metadata removal (#7376)
    
    ApplicationConfigCache stores the primary reference under the bare
    metadata path (cache.put(metaData.getPath(), reference)), but
    SofaMetaDataHandler.remove() and the changed-handle branch of handle()
    only called invalidateWithMetadataPath, whose segment scanner matches
    keys containing the KEY_SEPARATOR-wrapped token - which a bare path
    key can never contain. The primary entry therefore survived removal,
    so re-registering metadata under the same path with a different
    serviceName or registry reused the stale ConsumerConfig and invoked
    the old interface; the cache's removalListener (which exists precisely
    to clear consumerBootstrap for re-initialization) never fired either.
    The dubbo sibling invalidates both ways (invalidateReference calls
    invalidate(path) plus the segment-based variant); sofa now mirrors it
    in both call sites.
    
    The new test fails on current master (cached reference still present
    after remove) and passes with this change.
    
    Co-authored-by: Sean-Walker0 
<[email protected]>
---
 .../plugin/sofa/handler/SofaMetaDataHandler.java       |  3 +++
 .../plugin/sofa/handler/SofaMetaDataHandlerTest.java   | 18 ++++++++++++++++++
 2 files changed, 21 insertions(+)

diff --git 
a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-sofa/src/main/java/org/apache/shenyu/plugin/sofa/handler/SofaMetaDataHandler.java
 
b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-sofa/src/main/java/org/apache/shenyu/plugin/sofa/handler/SofaMetaDataHandler.java
index 754b2ee6b2..ae300e7b79 100644
--- 
a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-sofa/src/main/java/org/apache/shenyu/plugin/sofa/handler/SofaMetaDataHandler.java
+++ 
b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-sofa/src/main/java/org/apache/shenyu/plugin/sofa/handler/SofaMetaDataHandler.java
@@ -41,6 +41,8 @@ public class SofaMetaDataHandler implements MetaDataHandler {
             ApplicationConfigCache.getInstance().initRef(metaData);
         } else {
             if (!Objects.equals(exist.getServiceName(), 
metaData.getServiceName()) || !Objects.equals(exist.getRpcExt(), 
metaData.getRpcExt())) {
+                // mirror the dubbo handler's two-pronged invalidation: the 
bare-path key first, then the segment-based keys
+                
ApplicationConfigCache.getInstance().invalidate(metaData.getPath());
                 // remove old upstream reference
                 
ApplicationConfigCache.getInstance().invalidateWithMetadataPath(metaData.getPath());
                 // update
@@ -52,6 +54,7 @@ public class SofaMetaDataHandler implements MetaDataHandler {
     
     @Override
     public void remove(final MetaData metaData) {
+        ApplicationConfigCache.getInstance().invalidate(metaData.getPath());
         
ApplicationConfigCache.getInstance().invalidateWithMetadataPath(metaData.getPath());
         META_DATA.remove(metaData.getPath());
     }
diff --git 
a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-sofa/src/test/java/org/apache/shenyu/plugin/sofa/handler/SofaMetaDataHandlerTest.java
 
b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-sofa/src/test/java/org/apache/shenyu/plugin/sofa/handler/SofaMetaDataHandlerTest.java
index 2bf9e3271d..6819e818ff 100644
--- 
a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-sofa/src/test/java/org/apache/shenyu/plugin/sofa/handler/SofaMetaDataHandlerTest.java
+++ 
b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-sofa/src/test/java/org/apache/shenyu/plugin/sofa/handler/SofaMetaDataHandlerTest.java
@@ -33,6 +33,7 @@ import java.util.concurrent.ConcurrentMap;
 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -65,6 +66,23 @@ public class SofaMetaDataHandlerTest {
         assertDoesNotThrow(() -> sofaMetaDataHandler.handle(metaData));
     }
 
+    @Test
+    @SuppressWarnings("all")
+    public void removeShouldInvalidateThePlainPathCacheEntry() throws 
IllegalAccessException {
+        final String path = "sofa/plain-path-entry";
+        final MetaData metaData = MetaData.builder().path(path).build();
+        final Field cacheField = 
FieldUtils.getDeclaredField(ApplicationConfigCache.class, "cache", true);
+        assertNotNull(cacheField);
+        final LoadingCache cache = (LoadingCache) 
cacheField.get(ApplicationConfigCache.getInstance());
+        ConsumerConfig consumerConfig = mock(ConsumerConfig.class);
+        when(consumerConfig.refer()).thenReturn(mock(GenericService.class));
+        cache.put(path, consumerConfig);
+
+        sofaMetaDataHandler.remove(metaData);
+
+        assertNull(cache.getIfPresent(path), "remove() must invalidate the 
reference cached under the bare metadata path");
+    }
+
     @Test
     @SuppressWarnings("all")
     public void handleNullMetadataFieldsTest() throws IllegalAccessException {

Reply via email to