linghengqian opened a new pull request, #34463:
URL: https://github.com/apache/shardingsphere/pull/34463

   Fixes #33831.
   
   Changes proposed in this pull request:
     - Alleviate connection leaks caused by Seata Client throwing exceptions. 
The real connection leak bug occurs inside Seata Client `2.2.0`.
     - Fix 
https://github.com/apache/shardingsphere/actions/runs/12929853521/job/36060093185
 . Fix nativeTest failing due to class changes. Also for #29052 .
     - After closing DataSource, Seata Client's nativeTest will repeatedly 
throw exceptions due to an undocumented bug in Seata Client. At this time, the 
error handling of ShardingSphere is superimposed, resulting in a connection 
leak bug in other unit tests of the same module.
     - I personally have not confirmed how to gracefully close Seata Client, 
because ShardingSphere's existing integration tests even have to actively avoid 
the impact of https://github.com/apache/incubator-seata/pull/7044 . When Seata 
2.3.0 is released, I will revisit the bugs in the relevant unit tests. The use 
of `Awaitility.await().pollDelay(5L, TimeUnit.SECONDS).until(() -> true)` 
destroys the robustness of the unit test.
     - Previously, there was a connection leak in the unit test of 
`org.apache.shardingsphere.test.natived.jdbc.transactions.base.SeataTest`,
   ```shell
   [ERROR] 2025-01-24 12:45:38.606 [AsyncWorker_1_1_2] 
o.a.seata.rm.datasource.AsyncWorker - failed to get connection for async 
committing on jdbc:postgresql://localhost:33262/demo_ds_0 and requeue
   java.sql.SQLException: HikariDataSource HikariDataSource (HikariPool-4) has 
been closed.
        at 
com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:96)
        at 
org.apache.seata.rm.datasource.DataSourceProxy.getPlainConnection(DataSourceProxy.java:198)
        at 
org.apache.seata.rm.datasource.AsyncWorker.dealWithGroupedContexts(AsyncWorker.java:156)
        at java.base/java.util.HashMap.forEach(HashMap.java:1429)
        at 
org.apache.seata.rm.datasource.AsyncWorker.doBranchCommit(AsyncWorker.java:125)
        at 
org.apache.seata.rm.datasource.AsyncWorker.doBranchCommitSafely(AsyncWorker.java:107)
        at 
java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:572)
        at 
java.base/java.util.concurrent.FutureTask.runAndReset$$$capture(FutureTask.java:358)
        at 
java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java)
        at 
java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305)
        at 
java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
        at 
java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
        at 
io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.base/java.lang.Thread.run(Thread.java:1570)
   ```
     - Previously, there was a connection leak in the unit test of 
`org.apache.shardingsphere.test.natived.proxy.transactions.base.SeataTest`,
   ```shell
   [ERROR] 2025-01-24 13:25:46.951 [AsyncWorker_1_1_2] 
o.a.seata.rm.datasource.AsyncWorker - failed to get connection for async 
committing on jdbc:postgresql://127.0.0.1:33308/demo_ds_2 and requeue
   java.sql.SQLTransientConnectionException: HikariPool-4 - Connection is not 
available, request timed out after 30001ms.
           at 
com.zaxxer.hikari.pool.HikariPool.createTimeoutException(HikariPool.java:696)
           at 
com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:197)
           at 
com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:162)
           at 
com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:128)
           at 
org.apache.seata.rm.datasource.DataSourceProxy.getPlainConnection(DataSourceProxy.java:198)
           at 
org.apache.seata.rm.datasource.AsyncWorker.dealWithGroupedContexts(AsyncWorker.java:156)
           at java.base/java.util.HashMap.forEach(HashMap.java:1429)
           at 
org.apache.seata.rm.datasource.AsyncWorker.doBranchCommit(AsyncWorker.java:125)
           at 
org.apache.seata.rm.datasource.AsyncWorker.doBranchCommitSafely(AsyncWorker.java:107)
           at 
java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:572)
           at 
java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:358)
           at 
java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305)
           at 
java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
           at 
java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
           at 
io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
           at java.base/java.lang.Thread.run(Thread.java:1570)
   Caused by: org.postgresql.util.PSQLException: Connection to 127.0.0.1:33308 
refused. Check that the hostname and port are correct and that the postmaster 
is accepting TCP/IP connections.
           at 
org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:346)
           at 
org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:54)
           at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:273)
           at org.postgresql.Driver.makeConnection(Driver.java:446)
           at org.postgresql.Driver.connect(Driver.java:298)
           at 
com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138)
           at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:364)
           at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206)
           at 
com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:476)
           at com.zaxxer.hikari.pool.HikariPool.access$100(HikariPool.java:71)
           at 
com.zaxxer.hikari.pool.HikariPool$PoolEntryCreator.call(HikariPool.java:726)
           at 
com.zaxxer.hikari.pool.HikariPool$PoolEntryCreator.call(HikariPool.java:712)
           at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
           at 
java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
           at 
java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
           ... 1 common frames omitted
   Caused by: java.net.ConnectException: 连接被拒绝
           at java.base/sun.nio.ch.Net.pollConnect(Native Method)
           at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:682)
           at 
java.base/sun.nio.ch.NioSocketImpl.timedFinishConnect(NioSocketImpl.java:542)
           at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:592)
           at 
java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327)
           at java.base/java.net.Socket.connect(Socket.java:752)
           at org.postgresql.core.PGStream.createSocket(PGStream.java:243)
           at org.postgresql.core.PGStream.<init>(PGStream.java:98)
           at 
org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:136)
           at 
org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:262)
           ... 15 common frames omitted
   ```
   
   ---
   
   Before committing this PR, I'm sure that I have checked the following 
options:
   - [x] My code follows the [code of 
conduct](https://shardingsphere.apache.org/community/en/involved/conduct/code/) 
of this project.
   - [x] I have self-reviewed the commit code.
   - [x] I have (or in comment I request) added corresponding labels for the 
pull request.
   - [x] I have passed maven check locally : `./mvnw clean install -B -T1C 
-Dmaven.javadoc.skip -Dmaven.jacoco.skip -e`.
   - [ ] I have made corresponding changes to the documentation.
   - [x] I have added corresponding unit tests for my changes.
   - [x] I have updated the Release Notes of the current development version. 
For more details, see [Update Release 
Note](https://shardingsphere.apache.org/community/en/involved/contribute/contributor/)
   


-- 
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-unsubscr...@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to