You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by sh...@apache.org on 2026/06/19 14:33:56 UTC
(seatunnel) branch fix-jdbc-catalog-close-leak created (now d557261e46)
This is an automated email from the ASF dual-hosted git repository.
zhangshenghang pushed a change to branch fix-jdbc-catalog-close-leak
in repository https://gitbox.apache.org/repos/asf/seatunnel.git
at d557261e46 [Fix][Connector-V2] Close all JDBC catalog connections
This branch includes the following new commits:
new d557261e46 [Fix][Connector-V2] Close all JDBC catalog connections
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(seatunnel) 01/01: [Fix][Connector-V2] Close all JDBC catalog connections
Posted by sh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
zhangshenghang pushed a commit to branch fix-jdbc-catalog-close-leak
in repository https://gitbox.apache.org/repos/asf/seatunnel.git
commit d557261e465873afe2b79f83b364a8a8ed62508b
Author: zhangshenghang <sh...@apache.org>
AuthorDate: Fri Jun 19 22:33:36 2026 +0800
[Fix][Connector-V2] Close all JDBC catalog connections
---
.../jdbc/catalog/AbstractJdbcCatalog.java | 14 ++++-
.../jdbc/catalog/AbstractJdbcCatalogTest.java | 71 ++++++++++++++++++++++
2 files changed, 83 insertions(+), 2 deletions(-)
diff --git a/seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/catalog/AbstractJdbcCatalog.java b/seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/catalog/AbstractJdbcCatalog.java
index 83cec9eb1f..5ce68131bb 100644
--- a/seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/catalog/AbstractJdbcCatalog.java
+++ b/seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/catalog/AbstractJdbcCatalog.java
@@ -175,16 +175,26 @@ public abstract class AbstractJdbcCatalog implements Catalog {
@Override
public void close() throws CatalogException {
+ CatalogException closeException = null;
for (Map.Entry<String, Connection> entry : connectionMap.entrySet()) {
try {
entry.getValue().close();
} catch (SQLException e) {
- throw new CatalogException(
- String.format("Failed to close %s via JDBC.", entry.getKey()), e);
+ CatalogException currentException =
+ new CatalogException(
+ String.format("Failed to close %s via JDBC.", entry.getKey()), e);
+ if (closeException == null) {
+ closeException = currentException;
+ } else {
+ closeException.addSuppressed(currentException);
+ }
}
}
connectionMap.clear();
LOG.info("Catalog {} closing", catalogName);
+ if (closeException != null) {
+ throw closeException;
+ }
}
protected String getSelectColumnsSql(TablePath tablePath) {
diff --git a/seatunnel-connectors-v2/connector-jdbc/src/test/java/org/apache/seatunnel/connectors/seatunnel/jdbc/catalog/AbstractJdbcCatalogTest.java b/seatunnel-connectors-v2/connector-jdbc/src/test/java/org/apache/seatunnel/connectors/seatunnel/jdbc/catalog/AbstractJdbcCatalogTest.java
new file mode 100644
index 0000000000..c1a1abf389
--- /dev/null
+++ b/seatunnel-connectors-v2/connector-jdbc/src/test/java/org/apache/seatunnel/connectors/seatunnel/jdbc/catalog/AbstractJdbcCatalogTest.java
@@ -0,0 +1,71 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.jdbc.catalog;
+
+import org.apache.seatunnel.api.table.catalog.exception.CatalogException;
+import org.apache.seatunnel.common.utils.JdbcUrlUtil;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+class AbstractJdbcCatalogTest {
+
+ @Test
+ void shouldCloseRemainingConnectionsAndKeepSuppressedExceptionsWhenCloseFails()
+ throws SQLException {
+ TestJdbcCatalog catalog = new TestJdbcCatalog();
+ Connection failedConnection = mock(Connection.class);
+ Connection remainingConnection = mock(Connection.class);
+ doThrow(new SQLException("first close failed")).when(failedConnection).close();
+ doThrow(new SQLException("second close failed")).when(remainingConnection).close();
+ catalog.addConnection("jdbc:test:first", failedConnection);
+ catalog.addConnection("jdbc:test:second", remainingConnection);
+
+ CatalogException exception =
+ Assertions.assertThrows(CatalogException.class, catalog::close);
+
+ verify(failedConnection).close();
+ verify(remainingConnection).close();
+ Assertions.assertEquals(1, exception.getSuppressed().length);
+ }
+
+ private static class TestJdbcCatalog extends AbstractJdbcCatalog {
+
+ private TestJdbcCatalog() {
+ super(
+ "test",
+ "user",
+ "password",
+ new JdbcUrlUtil.UrlInfo(
+ "jdbc:test:default", "jdbc:test:", "localhost", 0, "default", null),
+ null,
+ null);
+ }
+
+ private void addConnection(String url, Connection connection) {
+ connectionMap.put(url, connection);
+ }
+ }
+}