Skip to content

Commit 93fe03a

Browse files
authored
fix(loadbalance): prevent panic in consistent hash toKey for non-string args (#3430)
The hard type assertion args[i].(string) panics for any non-string argument (int, struct, etc.), while Java Dubbo uses toString() which never fails. Replace with fmt.Fprint(&sb, args[i]) which safely converts any type to its string representation.
1 parent e741e0e commit 93fe03a

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

cluster/loadbalance/consistenthashing/selector.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (c *selector) toKey(args []any) string {
8585
var sb strings.Builder
8686
for i := range c.argumentIndex {
8787
if i >= 0 && i < len(args) {
88-
_, _ = fmt.Fprint(&sb, args[i].(string))
88+
_, _ = fmt.Fprint(&sb, args[i])
8989
}
9090
}
9191
return sb.String()

0 commit comments

Comments
 (0)