lesbass opened a new pull request, #3432: URL: https://github.com/apache/dubbo-go/pull/3432
## Summary Fixes #3431. In `cluster/loadbalance/consistenthashing/selector.go`, `toKey` was using the slice index from `range c.argumentIndex` as the argument position to read from `args`. With a configuration like `hash.arguments=1`, this still read `args[0]` instead of `args[1]`, causing consistent hashing to route by the wrong request argument. ## Changes 1. **`selector.go`**: Changed `for i := range c.argumentIndex` to `for _, i := range c.argumentIndex` so that `i` is the configured argument index, not the slice position. 2. **`selector.go`**: Replaced `args[i].(string)` with `fmt.Fprint(&sb, args[i])` to avoid panicking on non-string arguments. 3. **`loadbalance_test.go`**: Added `TestToKeyWithArgumentIndex` regression test with `hash.arguments=1` verifying that the key is built from the correct argument position. ## Verification ``` $ go test -v -count=1 ./cluster/loadbalance/consistenthashing/ === RUN TestConsistentHashSelectorSuite === RUN TestConsistentHashSelectorSuite/TestSelectForKey === RUN TestConsistentHashSelectorSuite/TestToKey --- PASS: TestConsistentHashSelectorSuite (0.00s) === RUN TestToKeyWithArgumentIndex --- PASS: TestToKeyWithArgumentIndex (0.00s) === RUN TestConsistentHashLoadBalanceSuite === RUN TestConsistentHashLoadBalanceSuite/TestConcurrentSelect === RUN TestConsistentHashLoadBalanceSuite/TestSelect --- PASS: TestConsistentHashLoadBalanceSuite (0.00s) PASS ok dubbo.apache.org/dubbo-go/v3/cluster/loadbalance/consistenthashing 0.007s ``` -- 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]
