Skip to content

Commit

Permalink
Fix connection leak in JDBC waitUntilContainerStarted (#5281)
Browse files Browse the repository at this point in the history
Only the Statement was auto-closed, but not the Connection
from which the Statement was created.

Aside from resources leaking, this can cause problems
when database rename transactions are executed by clients.
  • Loading branch information
rpygithub authored Apr 25, 2022
1 parent 600d235 commit 9660137
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.testcontainers.containers;

import com.github.dockerjava.api.command.InspectContainerResponse;
import java.sql.Statement;
import lombok.NonNull;
import lombok.SneakyThrows;
import org.apache.commons.lang3.StringUtils;
Expand All @@ -16,6 +15,7 @@
import java.sql.Connection;
import java.sql.Driver;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
Expand Down Expand Up @@ -144,7 +144,8 @@ protected void waitUntilContainerStarted() {
if (!isRunning()) {
Thread.sleep(100L);
} else {
try (Statement statement = createConnection("").createStatement()) {
try (Connection connection = createConnection("");
Statement statement = connection.createStatement()) {
boolean testQuerySucceeded = statement.execute(this.getTestQueryString());
if (testQuerySucceeded) {
logger().info("Container is started (JDBC URL: {})", this.getJdbcUrl());
Expand Down

0 comments on commit 9660137

Please sign in to comment.