eclipse-ee4j / eclipse-ee4j/jersey

Deadlock in Apache HTTP client for basic non-preemptive authentication

Open
#3,076 13 comments 0 reactions 0 assignees View on GitHub
Component: connectors Component: core Priority: Major Type: Bug
Dominant language
Java
Stars
730
Forks
382
PR merge metrics
No merged PRs in 30d

Description

I wanna share my experience about an issue that I encountered. The scenario is the following:

1\. jersey client
2\. http client connection manager
3\. apache connection provider
4\. basic non-preemptive authentication

the problem was that in some cases the connection was not released like expected, like the log below shows

```
2015-02-25 19:26:06.488 DEBUG 13230 --- [nio-8181-exec-9] h.i.c.PoolingHttpClientConnectionManager : Connection released: [id: 0][route: {}->http://localhost:8080][total kept alive: 1; route allocated: 1 of 10; total allocated: 1 of 10]
```

* Example that works in both cases, successful http code or not

```
rootTarget.queryParam("sort", sort + "," + dir)
.queryParam("size" + Integer.MAX_VALUE)
.request(MediaType.APPLICATION_JSON_TYPE).get(String.class);
```

* Example that works only if the request is unsuccessful

```
return rootTarget
.request(MediaType.WILDCARD_TYPE)
.post(Entity.entity(myobject, MediaType.APPLICATION_JSON_TYPE),
MyCustomClass.class);
```

* Example that doesn't work at all

```
Response r = null;
try {
r = idTarget.request(MediaType.WILDCARD_TYPE)
.put(Entity.entity(myobject, MediaType.APPLICATION_JSON_TYPE));
if (r.getStatusInfo().getStatusCode() != Status.NO_CONTENT
.getStatusCode()) {
throw new InternalServerErrorException(r.getStatusInfo()
.getReasonPhrase());
}
} finally {
if (r != null) {
try {
r.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
```

This last example works only if I consume the response body like string. Response.close() doesn't work.

Instead If I change the authentication to preemptive mode everything works fine.

Best regards
Mario Casola
#### Environment
Linux ubuntu 13.10, tomcat 7.0.57, jdk 1.7.0_71 64 bit
#### Affected Versions
[2.16]

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.