Discussion:
Force to release connection without waiting the final empty chunk arrival
Jim Ma
2018-04-12 07:44:30 UTC
Permalink
Hi,
When I tried to create http client with
a PoolingHttpClientConnectionManager and send get request to read the chunk
body with the following lines:
httpClient = HttpClientBuilder.create()
.setConnectionManager(poolingHttpClientConnectionManager)
.disableContentCompression().build();
...
HttpResposne res = httpClient.execute(httpGetMethod, ctx);
InputStream inputStream = res.getEntity().getContent();
//read inputstream

After read several bytes or not even read from InputStream, I'd like to
drop the response message and release the connection at any time without
waiting the empty chunk arrives.
But the inputstream here is an EofSensorInputStream which can only release
the connection after the response is consumed, so when I call
inputstream.close() it actually blocks there and wait the terminating
chunk.
Is there any approach that I can force to release this connection to pool
without discard it and make keep-alive work ?

Thanks,
Jim
Oleg Kalnichevski
2018-04-12 09:38:35 UTC
Permalink
Post by Jim Ma
Hi,
When I tried to create http client with
a PoolingHttpClientConnectionManager and send get request to read the chunk
  httpClient = HttpClientBuilder.create()
                 .setConnectionManager(poolingHttpClientConnectionMan
ager)
                 .disableContentCompression().build();
  ...
 HttpResposne res = httpClient.execute(httpGetMethod, ctx);
 InputStream inputStream = res.getEntity().getContent();
 //read inputstream
 After read several bytes or not even read from InputStream, I'd like
to
drop the response message and  release the connection at any time
without
waiting the empty chunk arrives.
 But the inputstream here is an EofSensorInputStream which can only
release
the connection after the response is consumed, so when I call
inputstream.close()  it actually blocks there and wait the
terminating
chunk.
Is there any approach that I can force to release this connection to pool
without discard it and make keep-alive work ?
Connection whose state is inconsistent cannot be re-used / kept alive.

Oleg

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org
Jim Ma
2018-04-13 02:50:35 UTC
Permalink
Thanks, Oleg. Can you please explain it more ? Do you mean the state of a
connection is inconsistent when the chunked inputstream isn't fully
consumed ?
Post by Oleg Kalnichevski
Post by Jim Ma
Hi,
When I tried to create http client with
a PoolingHttpClientConnectionManager and send get request to read the chunk
httpClient = HttpClientBuilder.create()
.setConnectionManager(poolingHttpClientConnectionMan
ager)
.disableContentCompression().build();
...
HttpResposne res = httpClient.execute(httpGetMethod, ctx);
InputStream inputStream = res.getEntity().getContent();
//read inputstream
After read several bytes or not even read from InputStream, I'd like to
drop the response message and release the connection at any time without
waiting the empty chunk arrives.
But the inputstream here is an EofSensorInputStream which can only release
the connection after the response is consumed, so when I call
inputstream.close() it actually blocks there and wait the
terminating
chunk.
Is there any approach that I can force to release this connection to pool
without discard it and make keep-alive work ?
Connection whose state is inconsistent cannot be re-used / kept alive.
Oleg
Oleg Kalnichevski
2018-04-13 08:27:44 UTC
Permalink
Thanks, Oleg. Can you please explain it more ?  Do you mean  the
state of a connection is inconsistent when the chunked inputstream
isn't fully consumed ?
If the connection were to be returned back to the pool and re-used for
another message exchange, the new consumer would get chunks of the
previous data stream in response to its request instead of a valid HTTP
response message.

Oleg
Post by Jim Ma
Post by Jim Ma
Hi,
When I tried to create http client with
a PoolingHttpClientConnectionManager and send get request to read
the
Post by Jim Ma
chunk
  httpClient = HttpClientBuilder.create()
                 .setConnectionManager(poolingHttpClientConnectionM
an
Post by Jim Ma
ager)
                 .disableContentCompression().build();
  ...
 HttpResposne res = httpClient.execute(httpGetMethod, ctx);
 InputStream inputStream = res.getEntity().getContent();
 //read inputstream
 After read several bytes or not even read from InputStream, I'd
like
Post by Jim Ma
to
drop the response message and  release the connection at any time
without
waiting the empty chunk arrives.
 But the inputstream here is an EofSensorInputStream which can
only
Post by Jim Ma
release
the connection after the response is consumed, so when I call
inputstream.close()  it actually blocks there and wait the
terminating
chunk.
Is there any approach that I can force to release this connection
to
Post by Jim Ma
pool
without discard it and make keep-alive work ?
Connection whose state is inconsistent cannot be re-used / kept alive.
Oleg
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org
Jim Ma
2018-04-13 08:54:33 UTC
Permalink
That makes sense.
In my case, there is long time connection and client waiting for the
terminating chunk to close the inputstream. Is there any approach that we
can
force to set the data stream chunk is terminating and this connection can
be released to pool ?
Post by Oleg Kalnichevski
Post by Jim Ma
Thanks, Oleg. Can you please explain it more ? Do you mean the
state of a connection is inconsistent when the chunked inputstream
isn't fully consumed ?
If the connection were to be returned back to the pool and re-used for
another message exchange, the new consumer would get chunks of the
previous data stream in response to its request instead of a valid HTTP
response message.
Oleg
Post by Jim Ma
Post by Jim Ma
Post by Jim Ma
Hi,
When I tried to create http client with
a PoolingHttpClientConnectionManager and send get request to read
the
Post by Jim Ma
chunk
httpClient = HttpClientBuilder.create()
.setConnectionManager(poolingHttpClientConnectionM
an
Post by Jim Ma
ager)
.disableContentCompression().build();
...
HttpResposne res = httpClient.execute(httpGetMethod, ctx);
InputStream inputStream = res.getEntity().getContent();
//read inputstream
After read several bytes or not even read from InputStream, I'd
like
Post by Jim Ma
to
drop the response message and release the connection at any time without
waiting the empty chunk arrives.
But the inputstream here is an EofSensorInputStream which can
only
Post by Jim Ma
release
the connection after the response is consumed, so when I call
inputstream.close() it actually blocks there and wait the terminating
chunk.
Is there any approach that I can force to release this connection
to
Post by Jim Ma
pool
without discard it and make keep-alive work ?
Connection whose state is inconsistent cannot be re-used / kept alive.
Oleg
Oleg Kalnichevski
2018-04-13 09:06:09 UTC
Permalink
Post by Jim Ma
That makes sense.
In my case, there is long time connection and client waiting for the
terminating chunk to close the inputstream. Is there any approach that we
can
force to set the data stream chunk is terminating and this connection can
be released to pool ?
Not unless one can open another connection, send a message and inform
the server to terminate the data stream. Overall, it would be massively
cheaper to drop the original connection in the first place.

Alternatively one could use HTTP/1.1 connection in a full duplex mode
to push chunks of data to the server or a HTTP/2 connection with proper
message multiplexing.

Oleg
Post by Jim Ma
Post by Oleg Kalnichevski
Thanks, Oleg. Can you please explain it more ?  Do you mean  the
state of a connection is inconsistent when the chunked
inputstream
isn't fully consumed ?
If the connection were to be returned back to the pool and re-used for
another message exchange, the new consumer would get chunks of the
previous data stream in response to its request instead of a valid HTTP
response message.
Oleg
org>
Post by Jim Ma
Post by Jim Ma
Hi,
When I tried to create http client with
a PoolingHttpClientConnectionManager and send get request to read
the
Post by Jim Ma
chunk
  httpClient = HttpClientBuilder.create()
                 .setConnectionManager(poolingHttpClientConnect
ionM
an
Post by Jim Ma
ager)
                 .disableContentCompression().build();
  ...
 HttpResposne res = httpClient.execute(httpGetMethod, ctx);
 InputStream inputStream = res.getEntity().getContent();
 //read inputstream
 After read several bytes or not even read from InputStream, I'd
like
Post by Jim Ma
to
drop the response message and  release the connection at any time
without
waiting the empty chunk arrives.
 But the inputstream here is an EofSensorInputStream which can
only
Post by Jim Ma
release
the connection after the response is consumed, so when I call
inputstream.close()  it actually blocks there and wait the
terminating
chunk.
Is there any approach that I can force to release this
connection
to
Post by Jim Ma
pool
without discard it and make keep-alive work ?
Connection whose state is inconsistent cannot be re-used / kept alive.
Oleg
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org
Jim Ma
2018-04-16 06:03:02 UTC
Permalink
Thanks for the explanation, Oleg.
I think we should discard this connection instead of trying to reuse it.
Is closing http response the right thing to discard this connection
immediately ?
​
Oleg Kalnichevski
2018-04-16 12:56:28 UTC
Permalink
Post by Jim Ma
Thanks for the explanation, Oleg.
I think we should discard this connection instead of trying to reuse it.
Is closing http response the right thing to discard this connection
immediately ?
Yes, it is.

Oleg

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org
Loading...