Alanxtl opened a new issue, #3431:
URL: https://github.com/apache/dubbo-go/issues/3431

   ## Problem
   
   In `cluster/loadbalance/consistenthashing/selector.go`, `newSelector` parses 
the configured `hash.arguments` values into `selector.argumentIndex`:
   
   ```go
   selector.argumentIndex = append(selector.argumentIndex, i)
   ```
   
   However, `toKey` currently iterates with `range` over the slice and uses the 
loop index instead of the configured value:
   
   ```go
   for i := range c.argumentIndex {
       if i >= 0 && i < len(args) {
           _, _ = fmt.Fprint(&sb, args[i])
       }
   }
   ```
   
   This means `methods.<method>.hash.arguments=1` still uses `args[0]`, because 
`i` is the position in `argumentIndex`, not the configured argument index.
   
   ## Example
   
   With:
   
   ```text
   methods.echo.hash.arguments=1
   args = []any{"tenantA", 42}
   ```
   
   Expected key should be based on `args[1]`, i.e. `"42"`.
   
   Actual key is based on `args[0]`, i.e. `"tenantA"`.
   
   This can make consistent hashing route by the wrong request argument and may 
produce different routing behavior from the configured intent and from Java 
Dubbo's implementation.
   
   ## Suggested fix
   
   Use the configured argument index values when building the key:
   
   ```go
   for _, i := range c.argumentIndex {
       if i >= 0 && i < len(args) {
           _, _ = fmt.Fprint(&sb, args[i])
       }
   }
   ```
   
   It would also be useful to add regression tests for non-zero 
`hash.arguments`, for example `hash.arguments=1` with `[]any{"ignored", 123}` 
should produce key `"123"`.
   


-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to