Skip to content

Commit

Permalink
Fix for connection leaks that only occurred in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
linghengqian committed Jan 14, 2025
1 parent 816307c commit 2f4e009
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource"},
"name":"JdkLogger"
},
{
"condition":{"typeReachable":"org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine"},
"name":"JdkLogger"
},
{
"condition":{"typeReachable":"org.apache.shardingsphere.mode.repository.standalone.jdbc.sql.JDBCRepositorySQLLoader"},
"name":"[Lcom.fasterxml.jackson.databind.deser.BeanDeserializerModifier;"
Expand All @@ -24,7 +28,7 @@
"name":"[Lcom.github.dockerjava.api.model.VolumesFrom;"
},
{
"condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.connection.DriverDatabaseConnectionManager$$Lambda/0x00007f2633df9040"},
"condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.connection.DriverDatabaseConnectionManager$$Lambda/0x00007fe65bdf1000"},
"name":"[Lcom.zaxxer.hikari.util.ConcurrentBag$IConcurrentBagEntry;"
},
{
Expand Down Expand Up @@ -745,6 +749,11 @@
"queryAllPublicConstructors":true,
"methods":[{"name":"<init>","parameterTypes":[] }, {"name":"add","parameterTypes":["long"] }, {"name":"sum","parameterTypes":[] }]
},
{
"condition":{"typeReachable":"org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask"},
"name":"java.util.concurrent.atomic.Striped64$Cell",
"fields":[{"name":"value"}]
},
{
"condition":{"typeReachable":"org.apache.shardingsphere.infra.expr.groovy.GroovyInlineExpressionParser"},
"name":"java.util.function.DoubleFunction",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.connection.DriverDatabaseConnectionManager"},
"pattern":"\\QMETA-INF/services/com.clickhouse.client.ClickHouseClient\\E"
}, {
"condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.connection.DriverDatabaseConnectionManager$$Lambda/0x00007f2633ca3d10"},
"condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.connection.DriverDatabaseConnectionManager$$Lambda/0x00007fe65bca0858"},
"pattern":"\\QMETA-INF/services/com.clickhouse.client.ClickHouseClient\\E"
}, {
"condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource"},
Expand Down Expand Up @@ -271,7 +271,7 @@
"condition":{"typeReachable":"org.apache.shardingsphere.proxy.frontend.postgresql.command.query.extended.Portal"},
"pattern":"\\QMETA-INF/services/org.apache.shardingsphere.infra.executor.checker.SQLExecutionChecker\\E"
}, {
"condition":{"typeReachable":"org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine"},
"condition":{"typeReachable":"org.apache.shardingsphere.proxy.frontend.postgresql.command.query.extended.Portal"},
"pattern":"\\QMETA-INF/services/org.apache.shardingsphere.infra.executor.sql.hook.SQLExecutionHook\\E"
}, {
"condition":{"typeReachable":"org.apache.shardingsphere.infra.executor.sql.prepare.AbstractExecutionPrepareEngine"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
"pattern":"\\QMETA-INF/services/javax.xml.parsers.SAXParserFactory\\E"
}]},
"bundles":[{
"name":"com.sun.org.apache.xml.internal.serializer.XMLEntities",
"locales":["en"]
}, {
"name":"com.microsoft.sqlserver.jdbc.SQLServerResource",
"locales":["en"]
}, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@

import lombok.Getter;
import org.apache.curator.test.InstanceSpec;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.proxy.Bootstrap;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.testcontainers.shaded.org.awaitility.Awaitility;

import javax.sql.DataSource;
import java.io.IOException;
import java.sql.SQLException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

/**
* This class is designed to start ShardingSphere Proxy directly in the current process,
Expand All @@ -48,18 +52,33 @@ public final class ProxyTestingServer {
public ProxyTestingServer(final String configAbsolutePath) {
completableFuture = CompletableFuture.runAsync(() -> {
try {
Bootstrap.main(new String[]{String.valueOf(proxyPort), configAbsolutePath, "0.0.0.0", "false"});
Bootstrap.main(new String[]{String.valueOf(proxyPort), configAbsolutePath, "0.0.0.0"});
} catch (final IOException | SQLException ex) {
throw new RuntimeException(ex);
}
});
}

/**
* Force close ShardingSphere Proxy. See {@link org.apache.shardingsphere.proxy.frontend.ShardingSphereProxy#close}.
* Force close ShardingSphere Proxy.
* For all Proxy related unit tests, the virtual database name is agreed to be `sharding_db`.
* See {@link org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource#close()} and
* {@link org.apache.shardingsphere.proxy.frontend.ShardingSphereProxy#close}.
*/
public void close() {
ProxyContext.getInstance().getContextManager().close();
completableFuture.cancel(false);
Awaitility.await().atMost(1L, TimeUnit.MINUTES).until(completableFuture::isDone);
ContextManager contextManager = ProxyContext.getInstance().getContextManager();
contextManager.getStorageUnits("sharding_db").values().forEach(storageUnit -> {
DataSource dataSource = storageUnit.getDataSource();
if (dataSource instanceof AutoCloseable) {
try {
((AutoCloseable) dataSource).close();
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
});
contextManager.close();
}
}

0 comments on commit 2f4e009

Please sign in to comment.