0z5a opened a new issue, #3863:
URL: https://github.com/apache/dubbo-go/issues/3863

   ### What happened?
   
   The consistent-hash load balancer caches one ring per `service.method` and 
rebuilds it only when a fingerprint of the invoker list changes. The 
fingerprint is `crc32` over `json.Marshal(invoker)` for each invoker 
(`cluster/loadbalance/consistenthashing/loadbalance.go`). The invoker types 
keep all their state in unexported fields (`base.BaseInvoker` holds `url`, 
`available`, `destroyed`; `DubboInvoker`, `TripleInvoker` and `FilterInvoker` 
add only unexported fields), so every invoker encodes as `{}`. The fingerprint 
therefore depends only on how many invokers there are.
   
   When the list changes but its length does not, the old ring stays in use and 
`Select` returns invokers that are no longer in the list it was given. This 
happens when:
   
   - a provider is replaced by another one, e.g. a rolling restart where the 
new instance comes up on a different address and the provider count stays the 
same. Keys that hashed to the old provider keep going to its invoker, which the 
directory has already removed.
   - a router gives different requests different provider subsets of the same 
size (tag or condition routing). The ring built for one subset is reused for 
the other, so requests can land on providers the router excluded.
   
   `BaseClusterInvoker.doSelectInvoker` does not catch this: when the picked 
invoker is unavailable it reselects from the list minus that invoker, but the 
picked invoker was not in the list, so the reselect list has the same length 
and hits the same cached ring.
   
   The Java implementation keys the cached selector on `invokers.hashCode()`, 
i.e. on which invoker objects are in the list, so it rebuilds in both cases.
   
   ### How can we reproduce it? (optional)
   
   Test in package `consistenthashing` on `develop` (ba67101):
   
   ```go
   func TestReproReplacedProvider(t *testing.T) {
        newInvoker := func(addr string) base.Invoker {
                u, _ := common.NewURL("dubbo://" + addr + 
"/org.apache.demo.DemoService")
                return base.NewBaseInvoker(u)
        }
        lb := newConshashLoadBalance()
        a, b, c := newInvoker("10.0.0.1:20000"), newInvoker("10.0.0.2:20000"), 
newInvoker("10.0.0.3:20000")
        call := func(i int) base.Invocation { return 
invocation.NewRPCInvocation("echo", []any{fmt.Sprint(i)}, nil) }
   
        for i := range 64 {
                lb.Select([]base.Invoker{a, b}, call(i))
        }
        current := []base.Invoker{c, b} // a was replaced by c
        stale := 0
        for i := range 64 {
                if got := lb.Select(current, call(i)); 
!slices.Contains(current, got) {
                        stale++
                }
        }
        t.Logf("%d of 64 keys went to an invoker that is not in the list", 
stale)
   }
   ```
   
   Output: `34 of 64 keys went to an invoker that is not in the list`. With the 
fingerprint taken from invoker identity instead, it prints `0 of 64`.
   
   ### Environment
   
   dubbo-go `develop` at ba67101, Go 1.27.1, macOS.
   


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