You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@seata.apache.org by xi...@apache.org on 2026/09/02 08:34:10 UTC

(incubator-seata-go) branch master updated: fix: correct XA connection hold fallback (#1150)

This is an automated email from the ASF dual-hosted git repository.

Ethan-Xingyue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-seata-go.git


The following commit(s) were added to refs/heads/master by this push:
     new 3bf73586 fix: correct XA connection hold fallback (#1150)
3bf73586 is described below

commit 3bf73586af81db1bd428982c93d82000d80cb1c8
Author: xiaobaicai66695 <57...@qq.com>
AuthorDate: Wed Sep 2 16:34:05 2026 +0800

    fix: correct XA connection hold fallback (#1150)
    
    Co-authored-by: Ethan <xi...@apache.org>
---
 pkg/datasource/sql/conn_xa.go      |  2 +-
 pkg/datasource/sql/conn_xa_test.go | 40 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/pkg/datasource/sql/conn_xa.go b/pkg/datasource/sql/conn_xa.go
index 71c98235..438f3523 100644
--- a/pkg/datasource/sql/conn_xa.go
+++ b/pkg/datasource/sql/conn_xa.go
@@ -579,7 +579,7 @@ func (c *XAConn) commitErrorHandle(ctx context.Context) error {
 }
 
 func (c *XAConn) ShouldBeHeld() bool {
-	return c.res.IsShouldBeHeld() || (c.res.GetDbType().String() != "" && c.res.GetDbType() != types.DBTypeUnknown)
+	return c.res.IsShouldBeHeld() || c.res.GetDbType() == types.DBTypeUnknown
 }
 
 func (c *XAConn) checkTimeout(ctx context.Context, now time.Time) error {
diff --git a/pkg/datasource/sql/conn_xa_test.go b/pkg/datasource/sql/conn_xa_test.go
index 4174b5a0..86595edc 100644
--- a/pkg/datasource/sql/conn_xa_test.go
+++ b/pkg/datasource/sql/conn_xa_test.go
@@ -261,6 +261,46 @@ func newMockXAConn(t *testing.T, ctrl *gomock.Controller, branchID int64) (*XACo
 	}, mockMgr
 }
 
+func TestXAConn_ShouldBeHeld(t *testing.T) {
+	tests := []struct {
+		name         string
+		dbType       types.DBType
+		resourceHold bool
+		want         bool
+	}{
+		{
+			name:         "resource requires owner connection",
+			dbType:       types.DBTypeMySQL,
+			resourceHold: true,
+			want:         true,
+		},
+		{
+			name:         "known database supports detached phase two",
+			dbType:       types.DBTypePostgreSQL,
+			resourceHold: false,
+			want:         false,
+		},
+		{
+			name:         "unknown database falls back to retaining connection",
+			dbType:       types.DBTypeUnknown,
+			resourceHold: false,
+			want:         true,
+		},
+	}
+
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			resource := &DBResource{
+				dbType:       tt.dbType,
+				shouldBeHeld: tt.resourceHold,
+			}
+			conn := &XAConn{Conn: &Conn{res: resource}}
+
+			assert.Equal(t, tt.want, conn.ShouldBeHeld())
+		})
+	}
+}
+
 func TestXAConn_ExecContext(t *testing.T) {
 
 	ctrl, db, mi, ti := initXAConnTestResource(t)


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org