Skip to content

Commit 952f753

Browse files
authored
Merge pull request #662 from BillyYccc/fix-pooled-connection-hang
Make recycling pooled connection events emitted on the eventloop context associated with connection pool
2 parents a9eeabb + 4ce65f3 commit 952f753

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

vertx-pg-client/src/test/java/io/vertx/pgclient/PgPoolTestBase.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ protected PgPool createPool(PgConnectOptions connectOptions, int size) {
5555

5656
@Test
5757
public void testPool(TestContext ctx) {
58-
int num = 1000;
58+
int num = 5000;
5959
Async async = ctx.async(num);
6060
PgPool pool = createPool(options, 4);
6161
for (int i = 0;i < num;i++) {
6262
pool.getConnection(ctx.asyncAssertSuccess(conn -> {
63-
conn.query("SELECT id, randomnumber from WORLD WHERE id = 1").execute(ar -> {
63+
conn.query("SELECT id, randomnumber from WORLD").execute(ar -> {
6464
if (ar.succeeded()) {
6565
SqlResult result = ar.result();
66-
ctx.assertEquals(1, result.size());
66+
ctx.assertEquals(10000, result.size());
6767
} else {
6868
ctx.assertEquals("closed", ar.cause().getMessage());
6969
}
@@ -80,10 +80,10 @@ public void testQuery(TestContext ctx) {
8080
Async async = ctx.async(num);
8181
PgPool pool = createPool(options, 4);
8282
for (int i = 0;i < num;i++) {
83-
pool.query("SELECT id, randomnumber from WORLD WHERE id = 1").execute(ar -> {
83+
pool.query("SELECT id, randomnumber from WORLD").execute(ar -> {
8484
if (ar.succeeded()) {
8585
SqlResult result = ar.result();
86-
ctx.assertEquals(1, result.size());
86+
ctx.assertEquals(10000, result.size());
8787
} else {
8888
ctx.assertEquals("closed", ar.cause().getMessage());
8989
}

vertx-sql-client/src/main/java/io/vertx/sqlclient/impl/pool/ConnectionPool.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,14 @@ public void init(Holder holder) {
169169

170170
@Override
171171
public void close(Holder holder, Promise<Void> promise) {
172+
if (context != null) {
173+
context.dispatch(v -> doClose(holder, promise));
174+
} else {
175+
doClose(holder, promise);
176+
}
177+
}
178+
179+
private void doClose(Holder holder, Promise<Void> promise) {
172180
if (holder != this.holder) {
173181
String msg;
174182
if (this.holder == null) {

0 commit comments

Comments
 (0)