This is an automated email from the ASF dual-hosted git repository.
davidzollo pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/seatunnel.git
The following commit(s) were added to refs/heads/dev by this push:
new 80c003c450 [Fix][Connector-V2] Close all JDBC catalog connections
(#11133)
80c003c450 is described below
commit 80c003c4502d85c279b40e7c4fdfa596f848f9e9
Author: Jast <[email protected]>
AuthorDate: Tue Jul 21 22:58:32 2026 +0800
[Fix][Connector-V2] Close all JDBC catalog connections (#11133)
---
.../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 665a3c7d27..9a40d2123f 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);
+ }
+ }
+}