apache/seatunnel · warning

JDBC connection close failed.

Error message

JDBC connection close failed.

What it means

SimpleJdbcConnectionProvider.closeConnection() validates then closes the single managed Connection; SQLException on close is logged as a warning and swallowed, and the connection field is always nulled in a finally block. This is deliberate best-effort cleanup: the provider never fails the task on close errors.

Source

Thrown at seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/connection/SimpleJdbcConnectionProvider.java:132

            // caller expectation.
            throw new JdbcConnectorException(
                    JdbcConnectorErrorCode.NO_SUITABLE_DRIVER,
                    "No suitable driver found for the configured JDBC URL");
        }

        connection.setAutoCommit(jdbcConfig.isAutoCommit());

        return connection;
    }

    @Override
    public void closeConnection() {
        try {
            if (isConnectionValid()) {
                connection.close();
            }
        } catch (SQLException e) {
            LOG.warn("JDBC connection close failed.", e);
        } finally {
            connection = null;
        }
    }

    @Override
    public Connection reestablishConnection() throws SQLException, ClassNotFoundException {
        closeConnection();
        return getOrEstablishConnection();
    }

    public JdbcConnectionConfig getJdbcConfig() {
        return jdbcConfig;
    }

    public void setConnection(Connection connection) {
        this.connection = connection;
    }

View on GitHub (pinned to cf67b549a7)

Solutions

  1. Fix the underlying disconnect cause (timeouts, LB idle limits, DB max_connections)
  2. Set TCP keepalive / socketTimeout in the JDBC URL so dead sockets fail fast
  3. Upgrade the JDBC driver if close of dead connections reliably throws
  4. Benign if it appears during reconnection and the new connection succeeds

Example fix

// before
jdbc:mysql://host:3306/db
// after
jdbc:mysql://host:3306/db?socketTimeout=300000&connectTimeout=60000&tcpKeepAlive=true
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-check before reestablish
if (connection != null && connection.isClosed()) {
    connection = null; // skip close, avoid SQLException path
}

Try / catch

// exception is swallowed internally (logged + connection nulled).
// For your own equivalent code:
try { if (conn != null) conn.close(); } catch (SQLException e) { LOG.warn("close failed", e); } finally { conn = null; }

Prevention

When it happens

Trigger: reestablishConnection() -> closeConnection() with a stale/broken connection; isConnectionValid() passes but connection.close() still throws (racy network failure, driver bug).

Common situations: Connection dropped by DB or intermediate LB between validation and close; drivers like older MySQL throwing on close of half-closed sockets; repeated during reconnection storms.

Understand the failure class

Background: ECONNREFUSED and "connection refused" / "could not connect to server" errors: what they mean and how to fix them — this error's family across 44 libraries.

Related errors


AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10). Data as JSON: /api/errors/a9c4ad03848cd676. Report an issue: GitHub.