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 467e6d2750 fix(admin): ignore the management server in the startup 
listener (#7789)
467e6d2750 is described below

commit 467e6d27506eb3650eba9a67ad0b4212d3891947
Author: Sean-Walker0 <[email protected]>
AuthorDate: Mon Oct 19 09:32:46 2026 +0800

    fix(admin): ignore the management server in the startup listener (#7789)
    
    ApplicationStartListener handled every WebServerInitializedEvent, so
    when the actuator management server (namespace "management") started
    on its own port, the listener called shenyuRunningModeService.start a
    second time with that port: standalone mode re-ran the checker setup
    and cluster mode scheduled an extra recurring election task.
    
    Skip events whose application context server namespace is
    "management". Regression test delivers a management-namespace
    ServletWebServerInitializedEvent and asserts the running mode service
    is never started for it (red on the previous code, which started it
    with the management port).
    
    Fixes #7775
    
    Co-authored-by: Sean-Walker0 
<[email protected]>
---
 .../admin/listener/ApplicationStartListener.java   |  8 ++++++++
 .../listener/ApplicationStartListenerTest.java     | 23 ++++++++++++++++++++++
 2 files changed, 31 insertions(+)

diff --git 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/listener/ApplicationStartListener.java
 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/listener/ApplicationStartListener.java
index cef056a09a..0689207efe 100644
--- 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/listener/ApplicationStartListener.java
+++ 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/listener/ApplicationStartListener.java
@@ -22,6 +22,7 @@ import org.apache.shenyu.admin.mode.ShenyuRunningModeService;
 import org.apache.shenyu.common.utils.IpUtils;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.web.context.WebServerInitializedEvent;
+import 
org.springframework.boot.web.servlet.context.ServletWebServerInitializedEvent;
 import org.springframework.context.ApplicationListener;
 import org.springframework.stereotype.Component;
 
@@ -40,6 +41,13 @@ public class ApplicationStartListener implements 
ApplicationListener<WebServerIn
     
     @Override
     public void onApplicationEvent(final WebServerInitializedEvent event) {
+        if (event instanceof ServletWebServerInitializedEvent servletEvent
+                && 
"management".equals(servletEvent.getApplicationContext().getServerNamespace())) 
{
+            // the management server is a side-channel, not another Admin 
instance:
+            // starting the running mode again would re-run checker setup and 
schedule
+            // an extra election task with the management port
+            return;
+        }
         int port = event.getWebServer().getPort();
         final String host = IpUtils.getHost();
         
diff --git 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/listener/ApplicationStartListenerTest.java
 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/listener/ApplicationStartListenerTest.java
index 935867fecc..e02b4c1cce 100644
--- 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/listener/ApplicationStartListenerTest.java
+++ 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/listener/ApplicationStartListenerTest.java
@@ -26,11 +26,18 @@ import org.mockito.InjectMocks;
 import org.mockito.Mock;
 import org.mockito.MockedStatic;
 import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
 import org.springframework.boot.web.server.WebServer;
 import org.springframework.boot.web.context.WebServerInitializedEvent;
 import org.springframework.test.util.ReflectionTestUtils;
 
+import static org.mockito.Mockito.lenient;
+import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.mockStatic;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
@@ -38,6 +45,7 @@ import static org.mockito.Mockito.when;
  * Test case for {@link ApplicationStartListener}.
  */
 @ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
 public final class ApplicationStartListenerTest {
 
     @InjectMocks
@@ -68,6 +76,21 @@ public final class ApplicationStartListenerTest {
         }
     }
 
+
+    @Test
+    void testIgnoresManagementServerEvent() {
+        final 
org.springframework.boot.web.servlet.context.ServletWebServerInitializedEvent 
servletEvent =
+                
mock(org.springframework.boot.web.servlet.context.ServletWebServerInitializedEvent.class);
+        final 
org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext 
managementContext =
+                
mock(org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.class);
+        lenient().when(servletEvent.getWebServer()).thenReturn(webServer);
+        
when(servletEvent.getApplicationContext()).thenReturn(managementContext);
+        when(managementContext.getServerNamespace()).thenReturn("management");
+
+        applicationStartListener.onApplicationEvent(servletEvent);
+        verify(shenyuRunningModeService, never()).start(anyString(), anyInt(), 
anyString());
+    }
+
     @Test
     void testOnApplicationEventWithEmptyContextPath() {
         ReflectionTestUtils.setField(applicationStartListener, "contextPath", 
"");

Reply via email to