Aias00 opened a new pull request, #3549:
URL: https://github.com/apache/dubbo-go/pull/3549
## What
`BuildInvokerChain` discarded the `bool` from `extension.GetFilter`, so an
unregistered filter name (typo / unimported) produced a `FilterInvoker` with a
nil `filter` that nil-derefs on the first `Invoke`.
## Why
```go
// protocol/protocolwrapper/protocol_filter_wrapper.go BuildInvokerChain
(before)
for _, filterName := range slices.Backward(filterNames) {
flt, _ := extension.GetFilter(strings.TrimSpace(filterName)) // bool
discarded
fi := &FilterInvoker{next: next, invoker: invoker, filter: flt} // flt
== nil if name unknown
next = fi
}
func (fi *FilterInvoker) Invoke(ctx, invocation) result.Result {
result := fi.filter.Invoke(ctx, fi.next, invocation) // nil interface
deref -> panic
return fi.filter.OnResponse(ctx, result, fi.invoker, invocation)
}
```
`extension.GetFilter` returns `(nil, false)` for an unknown name; the `bool`
is the intended signal and was thrown away. Setup succeeds; the first request
panics instead of failing at boot.
## Fix
Check the `bool` from `GetFilter`; on `!ok`, log an error and `continue`
(skip that filter, wrap the rest):
```go
flt, ok := extension.GetFilter(name)
if !ok {
logger.Errorf("[Protocol][Wrapper] filter %q is not registered, skip
it", name)
continue
}
```
## Tests
Added `TestBuildInvokerChainSkipsUnknownFilter`: a chain with
`mockEcho,unknownFilterName`; a non-echo invocation forces `mockEcho` to call
`next.Invoke` (which on the old code reached the nil-filter `FilterInvoker` and
panicked). Verified to **fail (panic)** on the old code and **pass** on the
fixed code. `protocol/protocolwrapper` passes under `-race`.
Fixes #3548
--
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]