Skip to content

Commit 477ca41

Browse files
hdfg159tsegismont
authored andcommitted
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 3f46b02 commit 477ca41

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,13 @@
1010
*/
1111
package io.vertx.httpproxy.impl;
1212

13-
import io.vertx.core.AsyncResult;
14-
import io.vertx.core.Future;
15-
import io.vertx.core.Handler;
16-
import io.vertx.core.MultiMap;
17-
import io.vertx.core.Promise;
13+
import io.vertx.core.*;
1814
import io.vertx.core.buffer.Buffer;
19-
import io.vertx.core.http.HttpClientRequest;
20-
import io.vertx.core.http.HttpHeaders;
21-
import io.vertx.core.http.HttpMethod;
22-
import io.vertx.core.http.HttpServerRequest;
23-
import io.vertx.core.http.HttpVersion;
15+
import io.vertx.core.http.*;
2416
import io.vertx.core.http.impl.HttpServerRequestInternal;
2517
import io.vertx.core.impl.ContextInternal;
18+
import io.vertx.core.impl.logging.Logger;
19+
import io.vertx.core.impl.logging.LoggerFactory;
2620
import io.vertx.core.net.HostAndPort;
2721
import io.vertx.core.streams.Pipe;
2822
import io.vertx.httpproxy.Body;
@@ -33,6 +27,7 @@
3327
import java.util.Objects;
3428

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

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

@@ -155,6 +150,14 @@ public ProxyResponse response() {
155150
}
156151

157152
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+
});
158161

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

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import io.vertx.core.streams.WriteStream;
2121
import io.vertx.ext.unit.Async;
2222
import io.vertx.ext.unit.TestContext;
23-
import org.junit.Ignore;
2423
import org.junit.Test;
2524

2625
import java.io.Closeable;
@@ -259,7 +258,7 @@ public void testFrontendCloseResponse(TestContext ctx) {
259258

260259
@Test
261260
public void testFrontendCloseChunkedResponse(TestContext ctx) {
262-
testBackendCloseResponse(ctx, true);
261+
testFrontendCloseResponse(ctx, true);
263262
}
264263

265264
private void testFrontendCloseResponse(TestContext ctx, boolean chunked) {
@@ -272,14 +271,12 @@ private void testFrontendCloseResponse(TestContext ctx, boolean chunked) {
272271
resp.putHeader("content-length", "10000");
273272
}
274273
resp.write("part");
275-
resp.exceptionHandler(err -> {
276-
async.complete();
277-
});
274+
resp.closeHandler(unused -> async.complete());
278275
});
279276
startProxy(backend);
280277
HttpClient client = vertx.createHttpClient();
281-
client.request(GET, 8081, "localhost", "/", ctx.asyncAssertSuccess(req -> {
282-
req.send(ctx.asyncAssertSuccess(resp -> {
278+
client.request(GET, 8080, "localhost", "/").onComplete(ctx.asyncAssertSuccess(req -> {
279+
req.send().onComplete(ctx.asyncAssertSuccess(resp -> {
283280
resp.handler(buff -> {
284281
resp.request().connection().close();
285282
System.out.println("closing");

0 commit comments

Comments
 (0)