Skip to content

Commit 32381a3

Browse files
authored
proxy httpclient does not release connection pool when frontend close chunked response (#90)
* Fix ProxyClientKeepAliveTest.testFrontendCloseChunkedResponse call method and port * Fix proxy httpclient does not release connection pool when frontend close chunked response.
1 parent c9d9dfc commit 32381a3

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/main/java/io/vertx/httpproxy/impl/ProxiedRequest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import io.vertx.core.http.*;
1616
import io.vertx.core.internal.ContextInternal;
1717
import io.vertx.core.internal.http.HttpServerRequestInternal;
18+
import io.vertx.core.internal.logging.Logger;
19+
import io.vertx.core.internal.logging.LoggerFactory;
1820
import io.vertx.core.net.HostAndPort;
1921
import io.vertx.core.streams.Pipe;
2022
import io.vertx.httpproxy.Body;
@@ -25,6 +27,7 @@
2527
import java.util.Objects;
2628

2729
public class ProxiedRequest implements ProxyRequest {
30+
private final static Logger log = LoggerFactory.getLogger(ProxiedRequest.class);
2831

2932
private static final CharSequence X_FORWARDED_HOST = HttpHeaders.createOptimized("x-forwarded-host");
3033

@@ -147,6 +150,14 @@ public ProxyResponse response() {
147150
}
148151

149152
void sendRequest(Handler<AsyncResult<ProxyResponse>> responseHandler) {
153+
proxiedRequest.connection().closeHandler(unused -> {
154+
if (log.isTraceEnabled()) {
155+
log.trace("Frontend connection closed,uri: " + proxiedRequest.uri());
156+
}
157+
158+
request.reset();
159+
proxiedRequest.response().reset();
160+
});
150161

151162
request.response().<ProxyResponse>map(r -> {
152163
r.pause(); // Pause it

src/test/java/io/vertx/tests/ProxyClientKeepAliveTest.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ public void testFrontendCloseResponse(TestContext ctx) {
266266

267267
@Test
268268
public void testFrontendCloseChunkedResponse(TestContext ctx) {
269-
testBackendCloseResponse(ctx, true);
269+
testFrontendCloseResponse(ctx, true);
270270
}
271271

272272
private void testFrontendCloseResponse(TestContext ctx, boolean chunked) {
@@ -279,13 +279,11 @@ private void testFrontendCloseResponse(TestContext ctx, boolean chunked) {
279279
resp.putHeader("content-length", "10000");
280280
}
281281
resp.write("part");
282-
resp.exceptionHandler(err -> {
283-
async.complete();
284-
});
282+
resp.closeHandler(unused -> async.complete());
285283
});
286284
startProxy(backend);
287285
client = vertx.createHttpClient();
288-
client.request(GET, 8081, "localhost", "/").onComplete(ctx.asyncAssertSuccess(req -> {
286+
client.request(GET, 8080, "localhost", "/").onComplete(ctx.asyncAssertSuccess(req -> {
289287
req.send().onComplete(ctx.asyncAssertSuccess(resp -> {
290288
resp.handler(buff -> {
291289
resp.request().connection().close();

0 commit comments

Comments
 (0)