Skip to content
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

Reproducer for leaking connection in XA mode #1919

Merged
merged 2 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ jobs:
./quarkus-dev-cli version
- name: Build with Maven
run: |
mvn -fae -V -B -s .github/mvn-settings.xml clean verify -Dinclude.quarkus-cli-tests -Dts.quarkus.cli.cmd="${PWD}/quarkus-dev-cli"${{ matrix.module-mvn-args }} -am
mvn -fae -V -B -s .github/mvn-settings.xml clean verify -Dinclude.quarkus-cli-tests -Dts.quarkus.cli.cmd="${PWD}/quarkus-dev-cli"${{ matrix.module-mvn-args }} -am -DexcludedGroups=long-running
- name: Detect flaky tests
id: flaky-test-detector
if: ${{ hashFiles('**/flaky-run-report.json') != '' }}
Expand Down Expand Up @@ -213,7 +213,7 @@ jobs:
mvn -fae -V -B -s .github/mvn-settings.xml -fae \
-Dquarkus.native.native-image-xmx=5g \
-Dinclude.quarkus-cli-tests -Dts.quarkus.cli.cmd="${PWD}/quarkus-dev-cli" \
${{ matrix.module-mvn-args }} clean verify -Dnative -am
${{ matrix.module-mvn-args }} clean verify -Dnative -am -DexcludedGroups=long-running
- name: Detect flaky tests
id: flaky-test-detector
if: ${{ hashFiles('**/flaky-run-report.json') != '' }}
Expand Down Expand Up @@ -264,7 +264,7 @@ jobs:
MODULES_MAVEN_PARAM="-pl ${MODULES_ARG}"
fi

mvn -B -fae -s .github/mvn-settings.xml clean verify -Dall-modules $MODULES_MAVEN_PARAM -am
mvn -B -fae -s .github/mvn-settings.xml clean verify -Dall-modules $MODULES_MAVEN_PARAM -am -DexcludedGroups=long-running
- name: Detect flaky tests
id: flaky-test-detector
if: ${{ hashFiles('**/flaky-run-report.json') != '' }}
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ The suite uses `org.junit.jupiter.api.Tag` annotation to group similar tests tog
- `serverless`: use Openshift Serverless to deploy the app
- `quarkus-cli`: tests use Quarkus CLI, which needs to be installed ( see https://quarkus.io/guides/cli-tooling for details)
- `podman-incompatible`: tests, which require Docker as a container engine and are not compatible with Podman.
- `long-running`: tests, which run for a long time and therefore are disabled in PR CI

## Running against Red Hat build of Quarkus

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
package io.quarkus.ts.service;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.core.Response;

import org.jboss.logging.Logger;

import io.agroal.api.AgroalDataSource;

@Path("/service")
public class ServiceResource {
private static final Logger LOG = Logger.getLogger(ServiceResource.class);

@Inject
AgroalDataSource defaultDataSource;

Expand All @@ -25,4 +31,20 @@ public Response grant(String user) throws SQLException {
return Response.status(status).build();
}
}

@Path("/connections")
@GET
public Response connections() {
try (Statement statement = defaultDataSource.getConnection().createStatement()) {
ResultSet set = statement.executeQuery("SELECT COUNT(*) from sys.dm_exec_connections;");
if (set.next()) {
int count = set.getInt(1);
return Response.ok(count).build();
}
return Response.serverError().build();
} catch (Exception e) {
LOG.error("Failed to retrieve number of connections", e);
return Response.serverError().build();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
import static io.quarkus.test.services.containers.DockerContainerManagedResource.DOCKER_INNER_CONTAINER;

import java.io.IOException;
import java.time.Duration;
import java.time.temporal.ChronoUnit;

import org.apache.http.HttpStatus;
import org.jboss.logging.Logger;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.GenericContainer;

import io.quarkus.test.bootstrap.RestService;
Expand All @@ -13,10 +20,12 @@
import io.quarkus.test.services.QuarkusApplication;
import io.quarkus.test.services.SqlServerContainer;
import io.quarkus.ts.transactions.recovery.TransactionExecutor;
import io.restassured.response.Response;

@DisabledOnFipsAndJava17(reason = "https://github.com/quarkusio/quarkus/issues/40813")
@QuarkusScenario
public class MssqlTransactionGeneralUsageIT extends TransactionCommons {
private static final Logger LOG = Logger.getLogger(MssqlTransactionGeneralUsageIT.class);

@SqlServerContainer
static SqlServerService database = new SqlServerService().onPostStart(service -> {
Expand Down Expand Up @@ -65,4 +74,24 @@ protected Operation[] getExpectedJdbcOperations() {
new Operation(actualOperationName -> actualOperationName.startsWith("UPDATE msdb.")) };
}

@Test
@Tag("long-running")
@Tag("QUARKUS-4185")
//on average, there is one leaking connection every 2 minutes
void connectionLeak() throws InterruptedException {
int before = getConnections();
Duration later = Duration.of(4L, ChronoUnit.MINUTES).plus(Duration.ofSeconds(15));
LOG.warn("Waiting for " + later.toSeconds() + " seconds to check for leaking connections");
Thread.sleep(later.toMillis());
fedinskiy marked this conversation as resolved.
Show resolved Hide resolved
int after = getConnections();
Assertions.assertFalse(after - before > 1, //single additional connection may be open temporary
"Connections are leaking, was: " + before + " now: " + after);

}

private int getConnections() {
Response response = getApp().given().get("/service/connections");
Assertions.assertEquals(HttpStatus.SC_OK, response.statusCode());
return Integer.parseInt(response.asString());
}
}
Loading