Repository navigation
Closed
Labels
Description
See the discussion here.
This test hangs after completing the first ~6 requests. The same happens on the release/3.0.x branch, but the release/2.0.x branch does not show this problem:
package com.graphhopper.application.resources;
import io.dropwizard.core.Application;
import io.dropwizard.core.Configuration;
import io.dropwizard.core.setup.Environment;
import io.dropwizard.testing.junit5.DropwizardAppExtension;
import io.dropwizard.testing.junit5.DropwizardExtensionsSupport;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Response;
@ExtendWith(DropwizardExtensionsSupport.class)
public class Dropwizard3Test {
@Path("/")
public static class MyResource {
@POST
public Response doPost() {
return Response.ok().build();
}
}
public static class MyApp extends Application<Configuration> {
@Override
public void run(Configuration configuration, Environment environment) throws Exception {
environment.jersey().register(new MyResource());
}
}
private static final DropwizardAppExtension<Configuration> app = new DropwizardAppExtension<>(MyApp.class, new Configuration());
@Test
public void myTest() {
for (int i = 0; i < 10; i++) {
post();
System.out.println("post " + i + " complete");
}
}
private static void post() {
Response response = app.client().target("http://localhost:8080/not_found").request().post(Entity.json("{}"));
System.out.println("success: " + response.getStatus());
}
}From my investigations it seems this is a client issue, which is "fixed" with:
app.client().property(Apache5ClientProperties.REUSE_STRATEGY, (ConnectionReuseStrategy) (request, response, context) -> false);But maybe the proper fix should be different?
@otbutz pointed out in the discussion that maybe response.close(); could be used as a fix? Or maybe the issue is related to #8884?
Activity
joschi commentedon Sep 1, 2024
@karussell Could you please try with the latest release (Dropwizard 4.0.8) which contains Jersey 3.0.15?
karussell commentedon Sep 3, 2024
Unfortunately it still hangs.
Here is what I tried:
I checkout a fresh dropwizard repository at 7cbfd4e (2024-08-31) and copied the above class into dropwizard-testing/src/test/java/io/dropwizard/testing/Dropwizard3Test.java ... a few imports are different - see the following file:
Details
Now either run
mvn clean install -pl dropwizard-testingor open the project in IntelliJ and run the test. In both cases it hangs at request number 4 and when I include the line with the REUSE_STRATEGY config it runs through successfully.zUniQueX commentedon Sep 14, 2024
Hi @karussell. Thanks for the example to reproduce the issue. However, your code doesn't explicitly close the
Response. The JavaDoc ofResponse#close()states:That means, the resources (e.g. threads) of the Apache client will only be released when the response is finally closed.
When modifying your
post()method to use try-with-resources the test runs without problems.I don't see this as a regression as the Jersey docs (Section 5.7) state one has to free the resources explicitly:
It seems that this wasn't an issue in previous versions because the Grizzly client didn't keep the resources busy as much as the Apache client does. However, from the implementation perspective everything works as intended.
Nevertheless, we could set the closing strategy as a convenience property as we already did with the compression.
karussell commentedon Sep 17, 2024
Thanks a lot for taking the time for this to investigate it. This makes a lot of sense - so closing here. We'll try this out soonish :)
easbar commentedon Sep 17, 2024
@zUniQueX I just looked at the migration from Dropwizard from version 3 to 4. The migration guide points to the migration guide for the Apache Http Client 5.x library where I found the
HttpClient#executemethod that returns aResponsewas deprecated in favor of a method consuming a response callback which closes the response automatically. DoesJerseyClientoffer something similar? Btw how come Dropwizard testing usesJerseyClienteven though Dropwizard already includes Apache client?zUniQueX commentedon Sep 17, 2024
@easbar The Jersey client is just a high level abstraction for http clients. Then a connector is utilized to defer the actual http part to another library like Apache http client.
The Apache http client 5.x has done a lot of effort towards streaming processing. For an easier migration, currently the synchronous compat API is used in the Jersey client connector.
Read body completely to release HTTP client resources (#9296)