Skip to content

[FLINK-32659] Fix the connection leak due to exception #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -249,33 +249,36 @@ protected void attemptFlush() throws SQLException {
/** Executes prepared statement and closes all resources of this instance. */
@Override
public synchronized void close() {
if (!closed) {
closed = true;
try {
if (!closed) {
closed = true;

if (this.scheduledFuture != null) {
scheduledFuture.cancel(false);
this.scheduler.shutdown();
}
if (this.scheduledFuture != null) {
scheduledFuture.cancel(false);
this.scheduler.shutdown();
}

if (batchCount > 0) {
try {
flush();
} catch (Exception e) {
LOG.warn("Writing records to JDBC failed.", e);
throw new RuntimeException("Writing records to JDBC failed.", e);
if (batchCount > 0) {
try {
flush();
} catch (Exception e) {
LOG.warn("Writing records to JDBC failed.", e);
throw new RuntimeException("Writing records to JDBC failed.", e);
}
}
}

try {
if (jdbcStatementExecutor != null) {
jdbcStatementExecutor.closeStatements();
try {
if (jdbcStatementExecutor != null) {
jdbcStatementExecutor.closeStatements();
}
} catch (SQLException e) {
LOG.warn("Close JDBC writer failed.", e);
}
} catch (SQLException e) {
LOG.warn("Close JDBC writer failed.", e);
}
} finally {
connectionProvider.closeConnection();
checkFlushException();
}
connectionProvider.closeConnection();
checkFlushException();
}

public static Builder builder() {
Expand Down