eclipse-ee4j / eclipse-ee4j/jersey
Grizzly connecter doesn't complete Future for some errors
- Dominant language
- Java
- Stars
- 730
- Forks
- 382
- PR merge metrics
- No merged PRs in 30d
Description
If I use the Grizzly connector to make an asynchronous call, some errors will cause the call to never return, leaving the caller waiting forever.
I have added repro code below. It makes an async call and simulates a failure when processing the response body:
* The InvocationCallback.failed method is never called.
* The Future is never completed.
* The process does not terminate.
```
import java.io.IOException;
import java.io.InputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.concurrent.Future;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.InvocationCallback;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.MessageBodyReader;
import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.grizzly.connector.GrizzlyConnectorProvider;
public class Test {
public static class MyClass {
}
public static class MyMessageBodyReader implements MessageBodyReader {
@Override
public boolean isReadable(Class type, Type genericType, Annotation[] annotations, MediaType mediaType) {
return true;
}
@Override
public MyClass readFrom(Class type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
throw new RuntimeException("Couldn't read message body.");
}
}
public static void main(String[] argv) throws Exception {
Client client = ClientBuilder.newClient(new ClientConfig()
.connectorProvider(new GrizzlyConnectorProvider()));
System.out.println("Calling...");
Future future = client.target("http://www.google.com")
.register(MyMessageBodyReader.class)
.request()
.async()
.get(new InvocationCallback() {
@Override
public void completed(MyClass response) {
System.out.println("Success!");
}
@Override
public void failed(Throwable throwable) {
System.out.println("Failed: " + throwable.getMessage());
}
});
System.out.println("Called.");
future.get();
System.out.println("Done.");
Thread.sleep(5000);
client.close();
}
}
```
#### Environment
Java8, Jersey client 2.25.1
#### Affected Versions
[2.25.1]
Contributor guide
Assessment
This issue has not been assessed yet.