You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@seata.apache.org by "KIRA-Zee (via GitHub)" <gi...@apache.org> on 2026/09/07 16:39:48 UTC
[PR] fix: avoid panic when BranchType has no ResourceManager [incubator-seata-go]
KIRA-Zee opened a new pull request, #1171:
URL: https://github.com/apache/incubator-seata-go/pull/1171
- [x] I have registered the PR [changes](https://github.com/apache/incubator-seata-go/tree/master/changes).
**What this PR does**:
Avoid panicking when BranchType has no ResourceManager; return a Failed branch response with xid and branch id.
**Which issue(s) this PR fixes**:
Fixes #1158
**Special notes for your reviewer**:
**Does this PR introduce a user-facing change?**:
```release-note
NONE
--
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@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] fix: avoid panic when BranchType has no ResourceManager [incubator-seata-go]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #1171:
URL: https://github.com/apache/incubator-seata-go/pull/1171#discussion_r4028718680
##########
pkg/rm/rm_cache.go:
##########
@@ -53,9 +52,18 @@ func (d *ResourceManagerCache) UnregisterResourceManager(branchType branch.Branc
}
func (d *ResourceManagerCache) GetResourceManager(branchType branch.BranchType) ResourceManager {
+ rm, _ := d.FindResourceManager(branchType)
+ return rm
+}
+
+func (d *ResourceManagerCache) FindResourceManager(branchType branch.BranchType) (ResourceManager, bool) {
rm, ok := d.resourceManagerMap.Load(branchType)
if !ok {
- panic(fmt.Sprintf("No ResourceManagerCache for BranchType: %v", branchType))
+ return nil, false
+ }
+ manager, ok := rm.(ResourceManager)
+ if !ok {
+ return nil, false
}
- return rm.(ResourceManager)
+ return manager, true
}
Review Comment:
`GetResourceManager` previously enforced correctness by panicking when the RM was absent; it now silently returns `nil`, which increases the chance of accidental `nil` dereferences at call sites and changes the contract without being obvious from the name. Consider (mandatory) adding a doc comment that explicitly states it returns `nil` when not found and directing callers to `FindResourceManager`, or (optionally) renaming/introducing a `MustGetResourceManager` helper if any internal paths still want fail-fast behavior.
##########
pkg/remoting/processor/client/rm_branch_rollback_processor.go:
##########
@@ -73,7 +73,18 @@ func (f *rmBranchRollbackProcessor) handleGrpcBranchRollback(ctx context.Context
ResourceId: resourceID,
ApplicationData: []byte(applicationData),
}
- status, err := rm.GetRmCacheInstance().GetResourceManager(branchType).BranchRollback(ctx, branchResource)
+ resourceManager, ok := rm.GetRmCacheInstance().FindResourceManager(branchType)
+ if !ok {
+ errMsg := resourceManagerNotFoundMsg(branchType)
+ log.Errorf("branch rollback error: %s", errMsg)
+ err := grpc.GetGrpcRemotingClient().SendAsyncResponse(rpcMessage.ID, newFailedGrpcBranchRollbackResponse(xid, branchID, errMsg))
Review Comment:
`resourceManagerNotFoundMsg` is defined in `rm_branch_commit_processor.go` (same package), so rollback now has an implicit cross-file dependency for a small helper. Consider moving shared helpers like `resourceManagerNotFoundMsg` into a dedicated shared file (e.g., `resource_manager_helpers.go`) near both processors to make reuse explicit and reduce the chance of accidental divergence.
##########
pkg/rm/issue1158_repro_test.go:
##########
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package rm
+
+import (
+ "testing"
+
+ "seata.apache.org/seata-go/v2/pkg/protocol/branch"
+)
+
+func TestUnknownBranchTypeReturnsErrorInsteadOfPanicking(t *testing.T) {
Review Comment:
The test name says \"ReturnsError\" but the assertion verifies a `nil` return (and absence of panic), not an error. Rename the test to reflect the actual behavior being validated (e.g., \"ReturnsNilInsteadOfPanicking\") to keep intent clear.
##########
pkg/rm/issue1158_repro_test.go:
##########
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package rm
+
+import (
+ "testing"
+
+ "seata.apache.org/seata-go/v2/pkg/protocol/branch"
+)
+
+func TestUnknownBranchTypeReturnsErrorInsteadOfPanicking(t *testing.T) {
+ defer func() {
+ if r := recover(); r != nil {
+ t.Fatalf("unknown branch type panicked: %v", r)
+ }
+ }()
+ if got := GetRmCacheInstance().GetResourceManager(branch.BranchType(99)); got != nil {
+ t.Fatalf("unexpected resource manager: %T", got)
+ }
+}
Review Comment:
The test name says \"ReturnsError\" but the assertion verifies a `nil` return (and absence of panic), not an error. Rename the test to reflect the actual behavior being validated (e.g., \"ReturnsNilInsteadOfPanicking\") to keep intent clear.
##########
pkg/rm/tcc/tcc_service.go:
##########
@@ -58,7 +58,13 @@ func NewTCCServiceProxy(service interface{}) (*TCCServiceProxy, error) {
func (t *TCCServiceProxy) RegisterResource() error {
var err error
t.registerResourceOnce.Do(func() {
- err = rm.GetRmCacheInstance().GetResourceManager(branch.BranchTypeTCC).RegisterResource(t.TCCResource)
+ mgr := rm.GetRmCacheInstance().GetResourceManager(branch.BranchTypeTCC)
+ if mgr == nil {
+ err = fmt.Errorf("no ResourceManager for BranchType: %v", branch.BranchTypeTCC)
+ log.Errorf("NewTCCServiceProxy RegisterResource error: %#v", err.Error())
+ return
+ }
+ err = mgr.RegisterResource(t.TCCResource)
if err != nil {
log.Errorf("NewTCCServiceProxy RegisterResource error: %#v", err.Error())
Review Comment:
The log call formats a `string` with `%#v` and also logs `err.Error()` rather than the `error` itself, which reduces clarity and can produce confusing output. Prefer logging `err` directly with `%v` (and avoid calling `Error()` here) so structured/typed error information is preserved.
--
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@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] fix: avoid panic when BranchType has no ResourceManager [incubator-seata-go]
Posted by "thunguo (via GitHub)" <gi...@apache.org>.
thunguo commented on PR #1171:
URL: https://github.com/apache/incubator-seata-go/pull/1171#issuecomment-6382092762
Plz resolve the conflicts.
--
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@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] fix: avoid panic when BranchType has no ResourceManager [incubator-seata-go]
Posted by "thunguo (via GitHub)" <gi...@apache.org>.
thunguo commented on code in PR #1171:
URL: https://github.com/apache/incubator-seata-go/pull/1171#discussion_r4028759352
##########
pkg/rm/issue1158_repro_test.go:
##########
@@ -0,0 +1,35 @@
+/*
Review Comment:
这里是不是不需要单独一个文件?
##########
pkg/remoting/processor/client/rm_branch_commit_processor.go:
##########
@@ -71,7 +72,19 @@ func (f *rmBranchCommitProcessor) handleGrpcBranchCommit(ctx context.Context, rp
Xid: xid,
}
- status, err := rm.GetRmCacheInstance().GetResourceManager(branch.BranchType(request.AbstractBranchEndRequest.BranchType)).BranchCommit(ctx, branchResource)
+ branchType := branch.BranchType(request.AbstractBranchEndRequest.BranchType)
Review Comment:
在转换前check下 BranchType是不是会好一些,int32 转 int8 后 257 会变成 TCC,未知类型会绕过检查走到已经注册的 RM。可以check下 pb.BranchTypeProto(branchType) != rawType,不一致返回 Failed。rollback 路径可以同样的处理。
--
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@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] fix: avoid panic when BranchType has no ResourceManager [incubator-seata-go]
Posted by "Ethan-Xingyue (via GitHub)" <gi...@apache.org>.
Ethan-Xingyue commented on PR #1171:
URL: https://github.com/apache/incubator-seata-go/pull/1171#issuecomment-5748253637
Verified locally: `go vet` and `go test -race` pass for rm, processor/client, saga store and datasource/sql. Direction is right, but a few things need attention:
Blocking:
1. The new not-found branches in the commit/rollback processors have no tests; both `*_test.go` files are untouched and Codecov shows ~10% patch coverage. #1158 acceptance criteria require an unknown-enum case for each getty and gRPC path. Please add: no panic, response is Failed, xid/branchId preserved.
2. +1 @thunguo: `pb.BranchTypeProto` is int32 and `branch.BranchType` is int8, so the direct conversion on the gRPC path truncates 257 to TCC and bypasses the check. Suggest an explicit switch accepting only AT/TCC/SAGA/XA and returning Failed otherwise. The getty path uses ReadByte and is not affected.
3. `GetResourceManager` is exported and is the `ResourceManagerGetter` contract. Changing panic to nil is a behavior change for external callers, so "user-facing change: NONE" is not accurate. Please add a doc comment stating it returns nil, and consider marking it Deprecated in favor of `FindResourceManager`.
Suggestions:
4. In both processors, when `BranchCommit`/`BranchRollback` fails the code does `return err` without replying, so TC waits for a timeout, while the new not-found path replies Failed. The two failure paths are inconsistent. Suggest one response builder for both, which also lets you drop the four new `newFailed*Response` helpers that duplicate the inline construction.
5. +1 @thunguo: fold `issue1158_repro_test.go` into `rm_cache_test.go` and add a direct assertion that `FindResourceManager` returns `(nil, false)`.
FYI, cross-checked with Java 2.x: a missing RM also replies Failed without a BranchStatus and TC treats it as retryable, so the behavior is consistent.
--
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@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] fix: avoid panic when BranchType has no ResourceManager [incubator-seata-go]
Posted by "XiaoFeiASK (via GitHub)" <gi...@apache.org>.
XiaoFeiASK commented on PR #1171:
URL: https://github.com/apache/incubator-seata-go/pull/1171#issuecomment-5645805156
please fix ci
--
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@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] fix: avoid panic when BranchType has no ResourceManager [incubator-seata-go]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #1171:
URL: https://github.com/apache/incubator-seata-go/pull/1171#issuecomment-5678241554
## [Codecov](https://app.codecov.io/gh/apache/incubator-seata-go/pull/1171?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:x: Patch coverage is `18.91892%` with `90 lines` in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 60.88%. Comparing base ([`3bf7358`](https://app.codecov.io/gh/apache/incubator-seata-go/commit/3bf73586af81db1bd428982c93d82000d80cb1c8?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`8e2c776`](https://app.codecov.io/gh/apache/incubator-seata-go/commit/8e2c7765bfc63002a4fe9263693736d199f9b5ad?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
| [Files with missing lines](https://app.codecov.io/gh/apache/incubator-seata-go/pull/1171?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
|---|---|---|
| [...ing/processor/client/rm\_branch\_commit\_processor.go](https://app.codecov.io/gh/apache/incubator-seata-go/pull/1171?src=pr&el=tree&filepath=pkg%2Fremoting%2Fprocessor%2Fclient%2Frm_branch_commit_processor.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGtnL3JlbW90aW5nL3Byb2Nlc3Nvci9jbGllbnQvcm1fYnJhbmNoX2NvbW1pdF9wcm9jZXNzb3IuZ28=) | 10.63% | [40 Missing and 2 partials :warning: ](https://app.codecov.io/gh/apache/incubator-seata-go/pull/1171?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [...g/processor/client/rm\_branch\_rollback\_processor.go](https://app.codecov.io/gh/apache/incubator-seata-go/pull/1171?src=pr&el=tree&filepath=pkg%2Fremoting%2Fprocessor%2Fclient%2Frm_branch_rollback_processor.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGtnL3JlbW90aW5nL3Byb2Nlc3Nvci9jbGllbnQvcm1fYnJhbmNoX3JvbGxiYWNrX3Byb2Nlc3Nvci5nbw==) | 9.09% | [38 Missing and 2 partials :warning: ](https://app.codecov.io/gh/apache/incubator-seata-go/pull/1171?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [pkg/rm/tcc/tcc\_service.go](https://app.codecov.io/gh/apache/incubator-seata-go/pull/1171?src=pr&el=tree&filepath=pkg%2Frm%2Ftcc%2Ftcc_service.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGtnL3JtL3RjYy90Y2Nfc2VydmljZS5nbw==) | 0.00% | [6 Missing :warning: ](https://app.codecov.io/gh/apache/incubator-seata-go/pull/1171?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [pkg/rm/rm\_cache.go](https://app.codecov.io/gh/apache/incubator-seata-go/pull/1171?src=pr&el=tree&filepath=pkg%2Frm%2Frm_cache.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGtnL3JtL3JtX2NhY2hlLmdv) | 75.00% | [1 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/incubator-seata-go/pull/1171?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## master #1171 +/- ##
==========================================
- Coverage 61.09% 60.88% -0.22%
==========================================
Files 309 309
Lines 22626 22722 +96
==========================================
+ Hits 13824 13834 +10
- Misses 7520 7602 +82
- Partials 1282 1286 +4
```
</details>
[:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/incubator-seata-go/pull/1171?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@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org