hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Oleg Kalnichevski (JIRA)" <j...@apache.org>
Subject [jira] [Resolved] (HTTPCLIENT-1815) CLONE - Request 'hangs' on invalid response from server
Date Fri, 17 Feb 2017 16:34:41 GMT

     [ https://issues.apache.org/jira/browse/HTTPCLIENT-1815?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel

Oleg Kalnichevski resolved HTTPCLIENT-1815.
    Resolution: Invalid

With all due respect but we cannot be expected to provide a work-around for each and every
craziness out there. If your application needs to be able to deal with completely insane garbage
please consider building a custom response parser as demonstrated below instead of bastardizing
the standard message transport logic.

With my custom parser the test case passes

    public void testNoContentResponseWithGarbage() throws Exception {
        this.serverBootstrap.setConnectionFactory(new BrokenServerConnectionFactory());
        this.serverBootstrap.registerHandler("/nostuff", new HttpRequestHandler() {

            public void handle(
                    final ClassicHttpRequest request,
                    final ClassicHttpResponse response,
                    final HttpContext context) throws HttpException, IOException {

        this.serverBootstrap.registerHandler("/stuff", new HttpRequestHandler() {

            public void handle(
                    final ClassicHttpRequest request,
                    final ClassicHttpResponse response,
                    final HttpContext context) throws HttpException, IOException {
                response.setEntity(new StringEntity("Some important stuff"));


        final PoolingHttpClientConnectionManager cm = PoolingHttpClientConnectionManagerBuilder.create()
                .setConnectionFactory(new ManagedHttpClientConnectionFactory(
                        new DefaultHttpRequestWriterFactory(),
                        new DefaultHttpResponseParserFactory() {

                            public HttpMessageParser<ClassicHttpResponse> create(final
H1Config h1Config) {
                                return new DefaultHttpResponseParser() {

                                    protected ClassicHttpResponse createMessage(final CharArrayBuffer
buffer) throws IOException, HttpException {
                                        try {
                                            return super.createMessage(buffer);
                                        } catch (HttpException ex) {
                                            return new BasicClassicHttpResponse(200);


        final HttpHost target = start();
        final HttpGet get1 = new HttpGet("/nostuff");
        try (CloseableHttpResponse response1 = this.httpclient.execute(target, get1)) {
            Assert.assertEquals(HttpStatus.SC_NO_CONTENT, response1.getCode());
        final HttpGet get2 = new HttpGet("/stuff");
        try (CloseableHttpResponse response2 = this.httpclient.execute(target, get2)) {
            Assert.assertEquals(HttpStatus.SC_OK, response2.getCode());


> CLONE - Request 'hangs' on invalid response from server
> -------------------------------------------------------
>                 Key: HTTPCLIENT-1815
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1815
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: Fluent HC, HttpClient (classic)
>         Environment: Java 8
> Running test with either Maven or IntelliJ.
>            Reporter: Gonzalo Berm├║dez
>         Attachments: TestMalformedServerResponse.java
> When using the fluent api to do a request and the response of the previous request was
status NoContent, but (!) the server did send some content anyway, then the next request is
blocked for a long time. No response is ever returned. Eventually some timeout will unblock
the thread, but the request has failed.
> To reproduce this issue:
> - create a server which returns a NoContent with some text body.
> - do a first request
> - do a second request. This request hangs/blocks the thread for long time.
> We're using Fluent API to easily unit test our rest api. In a test class where a test
was doing multiple requests, the first test would pass, but the second test would stall and
eventually fail. Individually the tests were passing. I could not find any issue on the server
side, so I tried another http client (Ning) which seemed to fix the issue. After rewriting
the test to use Ning instead of HttpClient, the tests were successful, but when I changed
it to reuse the same AsyncHttpClient, I got the same issue. However, because Ning does not
block but throws an exception, I was finally able to find the issue which caused the problem:
an endpoint returning a NoContent status, but with some text body.
> Even though this is a server issue, the httpclient should not block the thread for such
a long time and also return a proper error so this kind of issues so the cause is easier to
track down. Now, if I would not have used Ning, I would not have found the issue.
> The problem occurred when using Fluent Api, but I assume to cause for the thread to block
and not return a proper error is in the HttpClient component.

This message was sent by Atlassian JIRA

To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org

View raw message