Aias00 opened a new pull request, #3515:
URL: https://github.com/apache/dubbo-go/pull/3515

   ## What
   
   `base.doSelectInvoker` (and the `adaptivesvc` fast path) nil-dereference the 
result of `lb.Select` when a load-balance implementation returns `nil` for a 
non-empty invoker list, crashing the process on a transient error.
   
   ## Why
   
   Several `LoadBalance` implementations can return `nil` for non-empty input:
   
   - **P2C** (`cluster/loadbalance/p2c/loadbalance.go:128,139`) returns `nil` 
on a non-`ErrMetricsNotFound` metrics error, and `panic()` outright when the 
metrics value is not `uint64`.
   - **ConsistentHash** 
(`cluster/loadbalance/consistenthashing/loadbalance.go:71`) returns `nil` when 
`json.Marshal(invoker)` fails.
   
   `base/cluster_invoker.go:163` then calls `selectedInvoker.IsAvailable()` 
(and the reselect loop dereferences `reselectedInvoker`) with no nil guard → 
nil-pointer panic. The `adaptivesvc` fast path 
(`cluster/cluster/adaptivesvc/cluster_invoker.go:66-70`) forces P2C and 
dereferences the result the same way.
   
   ## Fix
   
   - `base.doSelectInvoker`: if `lb.Select` returns `nil` for the initial 
selection, warn and degrade to `invokers[0]`; on a `nil` reselect, stop 
retrying and fall through.
   - `adaptivesvc` fast path: degrade to `invokers[0]` when P2C returns `nil`.
   - `p2c`: replace the two `panic()` calls on an unexpected metrics type with 
`logger.Warnf` + `return nil`, so the cluster nil-guard can fall back instead 
of crashing.
   
   ## Tests
   
   Added `TestDoSelectDegradesWhenLbReturnsNil` with a nil-returning 
`LoadBalance` mock asserting `DoSelect` degrades to an invoker from the list 
rather than panicking. `p2c`, `base`, `adaptivesvc`, `consistenthashing` 
packages pass under `-race`.
   
   Note: `TestFailbackRetryFailed` / `TestRouteCacheGenerationRace` fail on 
`develop` HEAD already (pre-existing, unrelated to this change).
   
   Fixes #3513


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