Skip to content

Commit

Permalink
Revert "Reactive Rest Client closing connections after server failures"
Browse files Browse the repository at this point in the history
This reverts commit 23f9abc.

(cherry picked from commit bd57642)
  • Loading branch information
Sgitario authored and gsmet committed Dec 6, 2022
1 parent 47adaf9 commit c190ed8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 64 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package io.quarkus.rest.client.reactive;

import static io.restassured.RestAssured.given;
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;

import java.time.Duration;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -75,23 +72,4 @@ void shouldMapQueryParamsWithSpecialCharacters() {
assertThat(map.get("p5")).isEqualTo("5");
assertThat(map.get("p6")).isEqualTo("6");
}

/**
* Test to reproduce https://github.com/quarkusio/quarkus/issues/28818.
*/
@Test
void shouldCloseConnectionsWhenFailures() {
// It's using 30 seconds because it's the default timeout to release connections. This timeout should not be taken into
// account when there are failures, and we should be able to call 3 times to the service without waiting.
await().atMost(Duration.ofSeconds(30))
.until(() -> {
for (int call = 0; call < 3; call++) {
given()
.when().get("/hello/callClientForImageInfo")
.then()
.statusCode(500);
}
return true;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
Expand All @@ -24,10 +23,4 @@ public interface HelloClient2 {
@GET
@Path("delay")
Uni<String> delay();

@POST
@Path("/imageInfo")
@Consumes("image/gif")
@Produces(MediaType.TEXT_PLAIN)
String imageInfo(byte[] imageFile);
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,4 @@ public Uni<String> delay() {
return Uni.createFrom().item("Hello")
.onItem().delayIt().by(Duration.ofMillis(500));
}

@Path("callClientForImageInfo")
@GET
public String callClientForImageInfo() {
int size = 1024 * 1024 * 5;

byte[] buffer = new byte[size];

//Should provoke 415 Unsupported Media Type
return client2.imageInfo(buffer);
}

@POST
@Consumes({ "image/jpeg", "image/png" })
@Path("/imageInfo")
@Produces(MediaType.TEXT_PLAIN)
public String imageInfo(byte[] imageFile) {
throw new IllegalStateException("This method should never be invoked");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Variant;

import org.jboss.logging.Logger;
Expand Down Expand Up @@ -244,11 +243,6 @@ public void handle(HttpClientResponse clientResponse) {
}
}

if (Response.Status.Family.familyOf(status) != Response.Status.Family.SUCCESSFUL) {
httpClientRequest.connection().close();
requestContext.resume();
}

if (isResponseMultipart(requestContext)) {
QuarkusMultipartResponseDecoder multipartDecoder = new QuarkusMultipartResponseDecoder(
clientResponse);
Expand Down Expand Up @@ -372,16 +366,17 @@ public void handle(Buffer buffer) {
requestContext.resume(t);
}
}
}).onFailure(new Handler<>() {
@Override
public void handle(Throwable failure) {
if (failure instanceof IOException) {
requestContext.resume(new ProcessingException(failure));
} else {
requestContext.resume(failure);
}
}
});
})
.onFailure(new Handler<>() {
@Override
public void handle(Throwable failure) {
if (failure instanceof IOException) {
requestContext.resume(new ProcessingException(failure));
} else {
requestContext.resume(failure);
}
}
});
}

private boolean isResponseMultipart(RestClientRequestContext requestContext) {
Expand Down

0 comments on commit c190ed8

Please sign in to comment.