Hi Oleg,

Thank you for the Content-Length query which helped in determining the
actual cause of the issue. The problem was with sample code which is adding
entity object to request builder for all methods. Once added a hardcoded
check to create and add entity (i.e., instance of
*AbstractClassicEntityProducer*) only for POST, PATCH and PUT methods the
issue disappeared and we are able to get the response and now even
Content-Length header is not being sent in the request.

In 5.x sync implementation it seems all methods extend the
*HttpUriRequestBase* class and there is no way to avoid adding an entity to
a request object. In 4.5.x we have all entity available methods extending
*HttpEntityEnclosingRequestBase* and based on this we could determine
whether to add an entity to a request object or not. Is there anything
similar methodology available for Async implementation or 5.x httpclient
implementation as well through which we can determine for which request
method instances we need to add entity objects to requestbuilder instead of
the current hardcoded check for few methods?

Regards,
Sreenivas

On Wed, Feb 22, 2023 at 2:38 AM Oleg Kalnichevski <ol...@apache.org> wrote:

> On Wed, 2023-02-22 at 01:27 +0530, sreenivas somavarapu wrote:
> > Hi Team,
> >
> >
> > I have a perl script deployed on IIS server. When accessing this perl
> > script we are getting *Connection closed* error (see below for stack
> > trace)
> > from Async HTTPClient 5.2.x future callback. When further debugged
> > found
> > that IIS is sending “Connection: Close” header after the response is
> > sent
> > due to which http client is throwing the said error even after
> > reading /
> > processing the response. This is resulting in response lost what IIS
> > has
> > sent. When I access the same resource using browser it is able to
> > display
> > the content. Is there any mechanism to handle these kind of
> > responses?
> >
> >
>
> HttpClient by itself handles 'Connection: Close' correctly but your
> custom message exchange handling logic appears wrong. What I see from
> the exception stack trace is the client is still busy sending the
> request body when the server sends back the response and drops the
> connection on it, and the entire message exchange fails with the
> ConnectionClosedException as a result.
>
> And why on earth are you sending 'Content-Length: 0' with a GET
> request? Basically your request producing logic appears wrong.
>
> Oleg
>
>
> >
> > *Async HTTPClient Code*
> >
> > Future<Message<HttpResponse, String>> responseHandler =
> > httpAsyncClient.execute(reqBuilder.build(),
> >
> >                     new BasicResponseConsumer<>(new
> > AbstractClassicEntityConsumer<String>(){…}, null, clientContext,
> > null);
> >
> > *Message<HttpResponse, String> response = responseHandler.get();*
> >
> >  retCode = response.getHead().getCode();
> >
> >
> >
> > *Stack Trace / Exception stack*
> >
> > org.apache.hc.core5.http.ConnectionClosedException: Connection is
> > closed
> >
> >                at
> > org.apache.hc.core5.http.impl.nio.ClientHttp1StreamDuplexer.disconnec
> > ted(ClientHttp1StreamDuplexer.java:212)
> >
> >                at
> > org.apache.hc.core5.http.impl.nio.AbstractHttp1StreamDuplexer.onDisco
> > nnect(AbstractHttp1StreamDuplexer.java:409)
> >
> >                at
> > org.apache.hc.core5.http.impl.nio.AbstractHttp1IOEventHandler.disconn
> > ected(AbstractHttp1IOEventHandler.java:95)
> >
> >                at
> > org.apache.hc.core5.http.impl.nio.ClientHttp1IOEventHandler.disconnec
> > ted(ClientHttp1IOEventHandler.java:41)
> >
> >                at
> > org.apache.hc.client5.http.impl.async.LoggingIOSession$1.disconnected
> > (LoggingIOSession.java:258)
> >
> >                at
> > org.apache.hc.core5.reactor.InternalDataChannel.disconnected(Internal
> > DataChannel.java:204)
> >
> >                at
> > org.apache.hc.core5.reactor.SingleCoreIOReactor.processClosedSessions
> > (SingleCoreIOReactor.java:231)
> >
> >                at
> > org.apache.hc.core5.reactor.SingleCoreIOReactor.doExecute(SingleCoreI
> > OReactor.java:133)
> >
> >                at
> > org.apache.hc.core5.reactor.AbstractSingleCoreIOReactor.execute(Abstr
> > actSingleCoreIOReactor.java:86)
> >
> >                at
> > org.apache.hc.core5.reactor.IOReactorWorker.run(IOReactorWorker.java:
> > 44)
> >
> >                at java.lang.Thread.run(Thread.java:748)
> >
> >
> >
> >
> >
> > *HTTPClient log extract*
> >
> > 2023-02-21 15:37:59,600 DEBUG
> > [org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec]
> > ex-0000000003 send request GET /sample/ldapUD/16239/printenv.pl
> > HTTP/1.1,
> > entity len 0
> >
> > 2023-02-21 15:37:59,600 DEBUG [org.apache.hc.client5.http.headers]
> > c-0000000002 >> GET /printenv.pl HTTP/1.1
> >
> > 2023-02-21 15:37:59,600 DEBUG [org.apache.hc.client5.http.headers]
> > c-0000000002 >> Accept-Encoding: gzip, deflate
> >
> > 2023-02-21 15:37:59,600 DEBUG [org.apache.hc.client5.http.headers]
> > c-0000000002 >> SMSDOMAIN: .abc.net
> >
> > 2023-02-21 15:37:59,600 DEBUG [org.apache.hc.client5.http.headers]
> > c-0000000002 >> accept:
> > text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,imag
> > e/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
> >
> > 2023-02-21 15:37:59,600 DEBUG [org.apache.hc.client5.http.headers]
> > c-0000000002 >> Cache-Control: max-age=0
> >
> > 2023-02-21 15:37:59,600 DEBUG [org.apache.hc.client5.http.headers]
> > c-0000000002 >> Upgrade-Insecure-Requests: 1
> >
> > 2023-02-21 15:37:59,600 DEBUG [org.apache.hc.client5.http.headers]
> > c-0000000002 >> *connection: keep-alive*
> >
> > 2023-02-21 15:37:59,600 DEBUG [org.apache.hc.client5.http.headers]
> > c-0000000002 >> Accept-Language: en-US,en;q=0.9
> >
> > 2023-02-21 15:37:59,600 DEBUG [org.apache.hc.client5.http.headers]
> > c-0000000002 >> user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64)
> > AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36
> >
> > 2023-02-21 15:37:59,600 DEBUG [org.apache.hc.client5.http.headers]
> > c-0000000002 >> Content-Length: 0
> >
> > 2023-02-21 15:37:59,600 DEBUG [org.apache.hc.client5.http.headers]
> > c-0000000002 >> Host: iisserver
> >
> > 2023-02-21 15:37:59,600 DEBUG
> > [org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec]
> > ex-0000000003: produce request data
> >
> > ….
> >
> > ….
> >
> > ….
> >
> > 2023-02-21 15:37:59,647 DEBUG [org.apache.hc.client5.http.wire]
> > c-0000000002[ACTIVE][r:r] << 7N. .s..c...      37 4e fe 1f e3 73 1b
> > a9 63
> > 10 00 00
> >
> > 2023-02-21 15:37:59,647 DEBUG [org.apache.hc.client5.http.headers]
> > c-0000000002 << HTTP/1.1 200 OK
> >
> > 2023-02-21 15:37:59,647 DEBUG [org.apache.hc.client5.http.headers]
> > c-0000000002 << Content-Type: text/plain; charset=iso-8859-1
> >
> > 2023-02-21 15:37:59,647 DEBUG [org.apache.hc.client5.http.headers]
> > c-0000000002 << Content-Encoding: gzip
> >
> > 2023-02-21 15:37:59,647 DEBUG [org.apache.hc.client5.http.headers]
> > c-0000000002 << Vary: Accept-Encoding
> >
> > 2023-02-21 15:37:59,647 DEBUG [org.apache.hc.client5.http.headers]
> > c-0000000002 << Server: Microsoft-IIS/10.0
> >
> > 2023-02-21 15:37:59,647 DEBUG [org.apache.hc.client5.http.headers]
> > c-0000000002 << set-cookie: APPSESSION=abcd;Domain=.test.com;
> > Path=/default/xyz
> >
> > 2023-02-21 15:37:59,647 DEBUG [org.apache.hc.client5.http.headers]
> > c-0000000002 << X-Powered-By: ASP.NET
> >
> > 2023-02-21 15:37:59,647 DEBUG [org.apache.hc.client5.http.headers]
> > c-0000000002 << Date: Tue, 28 Feb 2023 03:41:23 GMT
> >
> > 2023-02-21 15:37:59,647 DEBUG [org.apache.hc.client5.http.headers]
> > c-0000000002 << *Connection: close*
> >
> > 2023-02-21 15:37:59,647 DEBUG [org.apache.hc.client5.http.headers]
> > c-0000000002 << Content-Length: 2170
> >
> > 2023-02-21 15:37:59,647 DEBUG
> > [org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec]
> > ex-0000000003: consume response HTTP/1.1 200 OK, entity len 2170
> >
> > 2023-02-21 15:37:59,647 DEBUG
> > [org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec]
> > ex-0000000003: consume response data, len 2170 bytes
> >
> > 2023-02-21 15:37:59,647 DEBUG
> > [org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec]
> > ex-0000000003: end of response data
> >
> > 2023-02-21 15:37:59,647 DEBUG
> > [org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient]
> > c-0000000002 Connection is not kept alive
> >
> > 2023-02-21 15:37:59,647 DEBUG
> > [org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec]
> > ex-0000000003: execution failed: Connection is closed
> >
> > 2023-02-21 15:37:59,647 DEBUG
> > [org.apache.hc.client5.http.impl.async.InternalAbstractHttpAsyncClien
> > t]
> > ex-0000000003 request failed: Connection is closed
> >
> > 2023-02-21 15:37:59,647 DEBUG
> > [org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionMana
> > ger]
> > ep-0000000003 close IMMEDIATE
> >
> > 2023-02-21 15:37:59,647 DEBUG
> > [org.apache.hc.client5.http.impl.nio.DefaultManagedAsyncClientConnect
> > ion]
> > c-0000000002 Shutdown connection IMMEDIATE
> >
> > 2023-02-21 15:37:59,647 DEBUG
> > [org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient]
> > ep-0000000003 endpoint closed
> >
> > 2023-02-21 15:37:59,647 DEBUG
> > [org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient]
> > ep-0000000003 discarding endpoint
> >
> > 2023-02-21 15:37:59,647 DEBUG
> > [org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionMana
> > ger]
> > ep-0000000003 releasing endpoint
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org
> For additional commands, e-mail: httpclient-users-h...@hc.apache.org
>
>

-- 
Cheers,
S. Sreenivas

Reply via email to