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

   ## Description
   
   Multiple single-value type assertions (`x.(T)` without the comma-ok form) 
will panic with `panic: interface conversion: ... is nil, not T` (or wrong 
concrete type) when the stored value does not match the expected type. These 
sit on hot paths such as service discovery and response decoding.
   
   ## Affected locations
   
   - `config_center/apollo/impl.go:121` — `return value.(string), nil` (panics 
when the Apollo value is not a string)
   - `registry/protocol/protocol.go:97` — `return 
actualReg.(registry.Registry)` (panics on type mismatch)
   - `registry/directory/directory.go:502,571,589` — multiple 
`value.(protocolbase.Invoker)` assertions
   - `protocol/dubbo/dubbo_codec.go:148-150` — 
`response.Result.(result.RPCResult)` (3 occurrences)
   - `filter/accesslog/filter.go:140-162` — `itf.(string)` etc. (8 occurrences 
on attachment values)
   
   ## Example risk
   
   ```go
   // config_center/apollo/impl.go:121
   return value.(string), nil
   // If value holds int/bool/nil, this panics instead of returning an error.
   ```
   
   ## Suggested fix
   
   Replace single-value assertions with the comma-ok form and return a 
descriptive error (or fall back gracefully):
   
   ```go
   s, ok := value.(string)
   if !ok {
       return "", perrors.Errorf("apollo value is not a string: %T", value)
   }
   return s, nil
   ```
   
   Apply the same pattern across the locations listed above.
   
   ## Severity
   
   P1 — incorrect config / unexpected data types cause hard panics on core RPC 
and discovery paths.
   
   ## Environment
   
   - Reproducible on current `develop` tip (3.3.2 prep).
   


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