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

jianbin pushed a commit to branch 2.x
in repository https://gitbox.apache.org/repos/asf/incubator-seata.git


The following commit(s) were added to refs/heads/2.x by this push:
     new 6614996930 bugfix: fix memory leak in MySQL XA mode (#7683)
6614996930 is described below

commit 661499693063a746a74ab6fb86f2dba76f85d802
Author: 软趴趴 <[email protected]>
AuthorDate: Fri Oct 10 10:28:20 2025 +0800

    bugfix: fix memory leak in MySQL XA mode (#7683)
---
 changes/en-us/2.x.md                               |  1 +
 changes/zh-cn/2.x.md                               |  1 +
 .../apache/seata/rm/datasource/xa/XABranchXid.java | 18 ++++++++
 .../seata/rm/datasource/xa/XABranchXidTest.java    | 48 ++++++++++++++++++++++
 4 files changed, 68 insertions(+)

diff --git a/changes/en-us/2.x.md b/changes/en-us/2.x.md
index b0400c79a5..dd79eceff7 100644
--- a/changes/en-us/2.x.md
+++ b/changes/en-us/2.x.md
@@ -44,6 +44,7 @@ Add changes here for all PR submitted to the 2.x branch.
 - [[#7624](https://github.com/apache/incubator-seata/pull/7624)] fix the 
compatibility issue of yml configuration files
 - [[#7644](https://github.com/apache/incubator-seata/pull/7644)] fix the 
compatibility issue of spotless when java 25
 - [[#7662](https://github.com/apache/incubator-seata/pull/7662)] ensure 
visibility of rm and The methods in MockTest are executed in order
+- [[#7683](https://github.com/apache/incubator-seata/pull/7683)] Override 
XABranchXid equals() and hashCode() to fix memory leak in mysql driver
 
 
 ### optimize:
diff --git a/changes/zh-cn/2.x.md b/changes/zh-cn/2.x.md
index 981153aff7..04979d80e4 100644
--- a/changes/zh-cn/2.x.md
+++ b/changes/zh-cn/2.x.md
@@ -44,6 +44,7 @@
 - [[#7624](https://github.com/apache/incubator-seata/pull/7624)] 
修复yml配置文件中对于整数的兼容问题
 - [[#7644](https://github.com/apache/incubator-seata/pull/7644)] 
修复JAVA25时spotless的兼容性问题
 - [[#7662](https://github.com/apache/incubator-seata/pull/7662)] 确保 rm 的可见性,并且 
MockTest 中的方法按顺序执行
+- [[#7683](https://github.com/apache/incubator-seata/pull/7683)] 重写 
XABranchXid的equals和hashCode,解决mysql driver内存泄漏问题
 
 
 ### optimize:
diff --git 
a/rm-datasource/src/main/java/org/apache/seata/rm/datasource/xa/XABranchXid.java
 
b/rm-datasource/src/main/java/org/apache/seata/rm/datasource/xa/XABranchXid.java
index 797d86c2f9..9de686f93a 100644
--- 
a/rm-datasource/src/main/java/org/apache/seata/rm/datasource/xa/XABranchXid.java
+++ 
b/rm-datasource/src/main/java/org/apache/seata/rm/datasource/xa/XABranchXid.java
@@ -17,6 +17,7 @@
 package org.apache.seata.rm.datasource.xa;
 
 import java.io.UnsupportedEncodingException;
+import java.util.Objects;
 
 /**
  * Xid in XA Protocol. Wrap info of Seata xid and branchId.
@@ -123,4 +124,21 @@ public class XABranchXid implements XAXid {
     public String toString() {
         return xid + BRANCH_ID_PREFIX + branchId;
     }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+        XABranchXid that = (XABranchXid) o;
+        return branchId == that.branchId && Objects.equals(xid, that.xid);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(xid, branchId);
+    }
 }
diff --git 
a/rm-datasource/src/test/java/org/apache/seata/rm/datasource/xa/XABranchXidTest.java
 
b/rm-datasource/src/test/java/org/apache/seata/rm/datasource/xa/XABranchXidTest.java
new file mode 100644
index 0000000000..8c0e92f22c
--- /dev/null
+++ 
b/rm-datasource/src/test/java/org/apache/seata/rm/datasource/xa/XABranchXidTest.java
@@ -0,0 +1,48 @@
+/*
+ * 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 org.apache.seata.rm.datasource.xa;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests for XABranchXid
+ */
+public class XABranchXidTest {
+    @Test
+    void testEquals() throws Exception {
+        XABranchXid xid1 = new XABranchXid("xid1", 1);
+        XABranchXid xid2 = new XABranchXid("xid1", 1);
+        XABranchXid xid3 = new XABranchXid("xid2", 2);
+        XABranchXid xid4 = null;
+
+        Assertions.assertEquals(xid1, xid2);
+        Assertions.assertNotEquals(xid1, xid3);
+        Assertions.assertNotEquals(xid1, xid4);
+        Assertions.assertNotEquals(xid1, new Object());
+    }
+
+    @Test
+    void testHashCode() throws Exception {
+        XABranchXid xid1 = new XABranchXid("xid1", 1);
+        XABranchXid xid2 = new XABranchXid("xid1", 1);
+        XABranchXid xid3 = new XABranchXid("xid2", 2);
+
+        Assertions.assertEquals(xid1.hashCode(), xid2.hashCode());
+        Assertions.assertNotEquals(xid1.hashCode(), xid3.hashCode());
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to