You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "Lcos-000 (via GitHub)" <gi...@apache.org> on 2026/08/19 10:42:13 UTC
[PR] fix(invocation): guard ActualMethodName type assertion to avoid panic [dubbo-go]
Lcos-000 opened a new pull request, #3684:
URL: https://github.com/apache/dubbo-go/pull/3684
### Description
Fixes #3683
`RPCInvocation.ActualMethodName()` (`protocol/invocation/rpcinvocation.go:89`) performed an unguarded type assertion on the first generic-call argument:
```go
func (r *RPCInvocation) ActualMethodName() string {
if r.IsGenericInvocation() {
return r.Arguments()[0].(string) // panics if arg[0] is not a string
}
return r.MethodName()
}
```
`IsGenericInvocation()` only checks `len(Arguments)==3`, not the element types. A malformed `$invoke` with a non-string `arg[0]` reached this line and panicked with `interface conversion: interface {} is X, not string`.
This is the same class of bug fixed in #3680 for `genericServiceFilter.Invoke`. In the default `DefaultServiceFilters` chain, `genericServiceFilter` runs before `otelServerFilter` and short-circuits malformed invocations, so `ActualMethodName()` is not reached by default. However, the filter order is user-configurable, and if a custom chain places `otelServerTrace` before `generic_service` (or omits `generic_service`), the panic becomes reachable on the server side via `filter/otel/trace/filter.go:83`.
This PR replaces the bare assertion with comma-ok form. Since `ActualMethodName() string` is an interface method on `base.Invocation` with no error return, it falls back to `r.MethodName()` on type mismatch (instead of returning an error like #3680 did). The interface signature is unchanged; all 7 call sites are unaffected.
### Checklist
- [x] I confirm the target branch is `develop`
- [x] I have run `make fmt` to format my code
- [x] I have run `make test` to run local tests
- [x] I have added tests that prove my fix is effective or that my feature works
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix(invocation): guard ActualMethodName type assertion to avoid panic [dubbo-go]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #3684:
URL: https://github.com/apache/dubbo-go/pull/3684#discussion_r3812662622
##########
protocol/invocation/rpcinvocation.go:
##########
@@ -84,10 +84,15 @@ func (r *RPCInvocation) MethodName() string {
// ActualMethodName gets actual invocation method name. It returns the method name been called if it's a generic call
func (r *RPCInvocation) ActualMethodName() string {
if r.IsGenericInvocation() {
- return r.Arguments()[0].(string)
- } else {
- return r.MethodName()
+ // IsGenericInvocation only guarantees len(Arguments)==3, not the element types;
+ // guard the assertion so a malformed $invoke falls back to MethodName() instead of panicking.
+ mtdName, ok := r.Arguments()[0].(string)
+ if !ok {
+ return r.MethodName()
+ }
+ return mtdName
Review Comment:
`r.Arguments()` is called inline during the assertion; consider assigning `args := r.Arguments()` once and then using `args[0]`. This avoids repeated method calls if `Arguments()` ever becomes non-trivial and makes the code easier to read.
##########
protocol/invocation/rpcinvocation_test.go:
##########
@@ -164,6 +164,33 @@ func TestRPCInvocation_ActualMethodName(t *testing.T) {
assert.Equal(t, "actualAsyncMethod", invocation.ActualMethodName())
}
+// TestRPCInvocation_ActualMethodName_MalformedArgs ensures a malformed $invoke
+// (arg[0] not a string) falls back to MethodName() instead of panicking.
+// See issue #3683.
+func TestRPCInvocation_ActualMethodName_MalformedArgs(t *testing.T) {
+ cases := []struct {
+ name string
+ method string
+ args []any
+ want string
+ }{
+ {name: "invoke-arg0-int", method: constant.Generic, args: []any{123, []string{}, []any{}}, want: constant.Generic},
+ {name: "invoke-arg0-nil", method: constant.Generic, args: []any{nil, []string{}, []any{}}, want: constant.Generic},
+ {name: "invokeAsync-arg0-int", method: constant.GenericAsync, args: []any{123, []string{}, []any{}}, want: constant.GenericAsync},
+ {name: "invokeAsync-arg0-nil", method: constant.GenericAsync, args: []any{nil, []string{}, []any{}}, want: constant.GenericAsync},
+ }
+ for _, tc := range cases {
+ t.Run(tc.name, func(t *testing.T) {
+ inv := NewRPCInvocationWithOptions(
+ WithMethodName(tc.method),
+ WithArguments(tc.args),
+ )
+ // Should fall back to MethodName() without panicking.
+ assert.Equal(t, tc.want, inv.ActualMethodName())
Review Comment:
This test will fail on panic implicitly, but it’s clearer and more intention-revealing to assert explicitly that `ActualMethodName()` does not panic (e.g., via an `assert.NotPanics`/`require.NotPanics` wrapper) and then assert the return value.
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix(invocation): guard ActualMethodName type assertion to avoid panic [dubbo-go]
Posted by "Alanxtl (via GitHub)" <gi...@apache.org>.
Alanxtl merged PR #3684:
URL: https://github.com/apache/dubbo-go/pull/3684
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix(invocation): guard ActualMethodName type assertion to avoid panic [dubbo-go]
Posted by "AlexStocks (via GitHub)" <gi...@apache.org>.
AlexStocks commented on PR #3684:
URL: https://github.com/apache/dubbo-go/pull/3684#issuecomment-5341777085
please take a look of the comment from copilot.
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix(invocation): guard ActualMethodName type assertion to avoid panic [dubbo-go]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #3684:
URL: https://github.com/apache/dubbo-go/pull/3684#issuecomment-5340997138
## [](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3684) **Quality Gate passed**
Issues
 [0 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3684&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3684&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3684&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3684&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3684&metric=new_duplicated_lines_density&view=list)
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3684)
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix(invocation): guard ActualMethodName type assertion to avoid panic [dubbo-go]
Posted by "Lcos-000 (via GitHub)" <gi...@apache.org>.
Lcos-000 commented on PR #3684:
URL: https://github.com/apache/dubbo-go/pull/3684#issuecomment-5341947972
i ve accepted 2 suggestions form copilot
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix(invocation): guard ActualMethodName type assertion to avoid panic [dubbo-go]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #3684:
URL: https://github.com/apache/dubbo-go/pull/3684#issuecomment-5341852701
## [Codecov](https://app.codecov.io/gh/apache/dubbo-go/pull/3684?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 55.27%. Comparing base ([`60d1c2a`](https://app.codecov.io/gh/apache/dubbo-go/commit/60d1c2a949f0ee0da4be3fe09fb79d295491e040?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`7300ac9`](https://app.codecov.io/gh/apache/dubbo-go/commit/7300ac96781694c9b82438394067835ab1d330de?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
:warning: Report is 938 commits behind head on develop.
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## develop #3684 +/- ##
===========================================
+ Coverage 46.76% 55.27% +8.50%
===========================================
Files 295 475 +180
Lines 17172 36818 +19646
===========================================
+ Hits 8031 20351 +12320
- Misses 8287 14845 +6558
- Partials 854 1622 +768
```
</details>
[:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/dubbo-go/pull/3684?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
</details>
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix(invocation): guard ActualMethodName type assertion to avoid panic [dubbo-go]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #3684:
URL: https://github.com/apache/dubbo-go/pull/3684#issuecomment-5341869171
## [](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3684) **Quality Gate passed**
Issues
 [0 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3684&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3684&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3684&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3684&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3684&metric=new_duplicated_lines_density&view=list)
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3684)
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org