bwangll opened a new issue, #6310:
URL: https://github.com/apache/shenyu/issues/6310

   ### Is there an existing issue for this?
   
   - [x] I have searched the existing issues
   
   ### Current Behavior
   
   ### Issue Description
   
     `ShenyuWebHandler.sortPlugins()` determines runtime plugin execution order 
by **prioritizing `PluginData.getSort()` (from DB)** over 
`PluginEnum.getCode()`:
   
     ```java
     // ShenyuWebHandler.java line 227-229
     PluginData pluginData = 
BaseDataCache.getInstance().obtainPluginData(plugin.named());
     return 
Optional.ofNullable(pluginData).map(PluginData::getSort).orElse(plugin.getOrder());
   
     However, several plugins have different values between PluginEnum (Java 
code) and db/init/mysql/schema.sql (initial DB data). This means:
   
     - The runtime order depends on whether the plugin has been synced from 
Admin (DB sort) or not (PluginEnum fallback)
     - Developers reading PluginEnum get a misleading picture of the actual 
execution order
   
     Affected Plugins
   
     ┌──────────────┬──────────────────────┬────────────────────┬───────┐
     │    Plugin    │ PluginEnum.getCode() │ DB schema.sql sort │ Delta │
     ├──────────────┼──────────────────────┼────────────────────┼───────┤
     │ keyAuth      │                  430 │                150 │  +280 │
     ├──────────────┼──────────────────────┼────────────────────┼───────┤
     │ resilience4j │                  150 │                310 │  -160 │
     ├──────────────┼──────────────────────┼────────────────────┼───────┤
     │ basicAuth    │                   35 │                150 │  -115 │
     ├──────────────┼──────────────────────┼────────────────────┼───────┤
     │ tcp          │                    0 │                320 │  -320 │
     ├──────────────┼──────────────────────┼────────────────────┼───────┤
     │ mqtt         │                    0 │                125 │  -125 │
     ├──────────────┼──────────────────────┼────────────────────┼───────┤
     │ mock         │                    8 │                  1 │    +7 │
     └──────────────┴──────────────────────┴────────────────────┴───────┘
   
     Impact
   
     The most significant inconsistency is keyAuth:
   
     - PluginEnum says order 430 (after Response at 420), suggesting it runs 
after the response is written
     - DB says sort 150, placing it in the Authentication phase (between WAF at 
50 and loggingConsole at 160), which is the correct semantic position
     - Since runtime uses DB sort, keyAuth actually works correctly in 
production — but the code is misleading
   
     Suggested Fix
   
     Align PluginEnum.getCode() values with schema.sql sort values. The DB 
values appear to reflect the intended design (e.g., keyAuth in Authentication 
category at 150). Recommend updating PluginEnum to
     match:
   
     // Current → Proposed
     KEY_AUTH(430, 0, "keyAuth")        → KEY_AUTH(150, 0, "keyAuth")
     RESILIENCE4J(150, 0, "resilience4j") → RESILIENCE4J(310, 0, "resilience4j")
     BASIC_AUTH(35, 0, "basicAuth")     → BASIC_AUTH(150, 0, "basicAuth")
     TCP(0, 0, "tcp")                   → TCP(320, 0, "tcp")
     MQTT(0, 0, "mqtt")                 → MQTT(125, 0, "mqtt")
     MOCK(8, 0, "mock")                 → MOCK(1, 0, "mock")
   
     Also recommend adding a unit test to prevent future drift:
   
     @Test
     void pluginEnumShouldMatchDbSort() {
         // Parse schema.sql and verify each plugin's PluginEnum.getCode()
         // matches the DB sort value
     }
   
     Environment
   
     - ShenYu version: 2.7.0+
     - Source: master branch
   
   ### Expected Behavior
   
   _No response_
   
   ### Steps To Reproduce
   
   _No response_
   
   ### Environment
   
   ```markdown
   ShenYu version(s):
   ```
   
   ### Debug logs
   
   _No response_
   
   ### Anything else?
   
   _No response_


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to