Re: How can I abort an aynsc request using HttpAsyncClient
I want to start an async GET request for a big file. Then, at some point, while the content is still being received, I would like to cancel the request from another thread and close all relevant resources. I tried to achieve this behaviour by implementing AsyncByteConsumer and doing something like the following, but I have the feeling that the connection from the connection pool was not released: … @Override protected void onByteReceived(ByteBuffer buf, IOControl ioctrl) throws IOException { … ioctrl.shutdown(); … } … Also, I read in documentation that using “shutdown” on a channel is bad for SSL connections, where “close” should be called instead. Thanks, Yoram On February 17, 2014 at 11:16:03 AM, Oleg Kalnichevski (ol...@apache.org) wrote: On Sun, 2014-02-16 at 16:30 +0200, Yoram Dayagi (Gmail) wrote: Hi I would like to use HttpAsyncClient in order to execute async requests. Is it possible to abort an executing request from another thread? What exactly do you mean by aborting request execution? Unblocking a thread awaiting on the result future? Shutting down the underlying connection? What is it exactly you are trying to achieve? Oleg - To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org For additional commands, e-mail: httpclient-users-h...@hc.apache.org
Re: How can I abort an aynsc request using HttpAsyncClient
On Mon, 2014-02-17 at 11:23 +0200, Yoram Dayagi (Gmail) wrote: I want to start an async GET request for a big file. Then, at some point, while the content is still being received, I would like to cancel the request from another thread and close all relevant resources. I tried to achieve this behaviour by implementing AsyncByteConsumer and doing something like the following, but I have the feeling that the connection from the connection pool was not released: … @Override protected void onByteReceived(ByteBuffer buf, IOControl ioctrl) throws IOException { … ioctrl.shutdown(); … } … This looks correct to me. Why do you think the connection was not released back to the pool? You can run your client with connection management context logging turned out to find out whether of not the pool was leaking connections. http://hc.apache.org/httpcomponents-client-4.3.x/logging.html Also, I read in documentation that using “shutdown” on a channel is bad for SSL connections, where “close” should be called instead. Given you are shutting down the connection in the middle of an HTTP exchange I doubt that should matter. Oleg - To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org For additional commands, e-mail: httpclient-users-h...@hc.apache.org
Re: How can I abort an aynsc request using HttpAsyncClient
Hi Below is the log of the following scenario: 1. Create an async client with MaxConnPerRoute=1 2. Start a request 3. Wait for 100ms and shutdown the channel (using ioctrl.shutdown) 4. Wait for 2000ms and start another request for same url 2014/02/17 12:34:15:587 IST [DEBUG] PoolingNHttpClientConnectionManager - Connection request: [route: {}-http://966b.http.dal05.cdn.softlayer.net:80][total kept alive: 0; route allocated: 0 of 1; total allocated: 0 of 10] 2014/02/17 12:34:15:681 IST [DEBUG] PoolingNHttpClientConnectionManager - Connection leased: [id: http-outgoing-0][route: {}-http://966b.http.dal05.cdn.softlayer.net:80][total kept alive: 0; route allocated: 1 of 1; total allocated: 1 of 10] 2014/02/17 12:34:15:689 IST [DEBUG] ManagedNHttpClientConnectionImpl - http-outgoing-0 10.0.0.2:58623-93.184.221.133:80[ACTIVE][r:]: Set attribute http.nio.exchange-handler 2014/02/17 12:34:15:690 IST [DEBUG] ManagedNHttpClientConnectionImpl - http-outgoing-0 10.0.0.2:58623-93.184.221.133:80[ACTIVE][rw:]: Event set [w] 2014/02/17 12:34:15:691 IST [DEBUG] ManagedNHttpClientConnectionImpl - http-outgoing-0 10.0.0.2:58623-93.184.221.133:80[ACTIVE][rw:]: Set attribute http.nio.http-exchange-state 2014/02/17 12:34:15:692 IST [DEBUG] ManagedNHttpClientConnectionImpl - http-outgoing-0 10.0.0.2:58623-93.184.221.133:80[ACTIVE][rw:]: Event set [w] 2014/02/17 12:34:15:694 IST [DEBUG] ManagedNHttpClientConnectionImpl - http-outgoing-0 10.0.0.2:58623-93.184.221.133:80[ACTIVE][rw:w]: 246 bytes written 2014/02/17 12:34:15:694 IST [DEBUG] ManagedNHttpClientConnectionImpl - http-outgoing-0 10.0.0.2:58623-93.184.221.133:80[ACTIVE][r:w]: Event cleared [w] 2014/02/17 12:34:15:770 IST [DEBUG] ManagedNHttpClientConnectionImpl - http-outgoing-0 10.0.0.2:58623-93.184.221.133:80[ACTIVE][r:r]: 1360 bytes read 2014/02/17 12:34:15:775 IST [DEBUG] ManagedNHttpClientConnectionImpl - http-outgoing-0 10.0.0.2:58623-93.184.221.133:80[ACTIVE][r:r]: Shutdown 2014/02/17 12:34:17:695 IST [DEBUG] PoolingNHttpClientConnectionManager - Connection request: [route: {}-http://966b.http.dal05.cdn.softlayer.net:80][total kept alive: 0; route allocated: 1 of 1; total allocated: 1 of 10] Note that the last log of “Connection request” reports that “route allocated: 1 of 1”. Doesn’t it mean that the connection was not released when the channel was shut down? From the client perspective, the consumer’s onByteReceived is never called after this point. Thanks, Yoram On February 17, 2014 at 11:46:15 AM, Oleg Kalnichevski (ol...@apache.org) wrote: On Mon, 2014-02-17 at 11:23 +0200, Yoram Dayagi (Gmail) wrote: I want to start an async GET request for a big file. Then, at some point, while the content is still being received, I would like to cancel the request from another thread and close all relevant resources. I tried to achieve this behaviour by implementing AsyncByteConsumer and doing something like the following, but I have the feeling that the connection from the connection pool was not released: … @Override protected void onByteReceived(ByteBuffer buf, IOControl ioctrl) throws IOException { … ioctrl.shutdown(); … } … This looks correct to me. Why do you think the connection was not released back to the pool? You can run your client with connection management context logging turned out to find out whether of not the pool was leaking connections. http://hc.apache.org/httpcomponents-client-4.3.x/logging.html Also, I read in documentation that using “shutdown” on a channel is bad for SSL connections, where “close” should be called instead. Given you are shutting down the connection in the middle of an HTTP exchange I doubt that should matter. Oleg - To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org For additional commands, e-mail: httpclient-users-h...@hc.apache.org
Re: How can I abort an aynsc request using HttpAsyncClient
On Mon, 2014-02-17 at 12:40 +0200, Yoram Dayagi (Gmail) wrote: Hi Below is the log of the following scenario: 1. Create an async client with MaxConnPerRoute=1 2. Start a request 3. Wait for 100ms and shutdown the channel (using ioctrl.shutdown) 4. Wait for 2000ms and start another request for same url 2014/02/17 12:34:15:587 IST [DEBUG] PoolingNHttpClientConnectionManager - Connection request: [route: {}-http://966b.http.dal05.cdn.softlayer.net:80][total kept alive: 0; route allocated: 0 of 1; total allocated: 0 of 10] 2014/02/17 12:34:15:681 IST [DEBUG] PoolingNHttpClientConnectionManager - Connection leased: [id: http-outgoing-0][route: {}-http://966b.http.dal05.cdn.softlayer.net:80][total kept alive: 0; route allocated: 1 of 1; total allocated: 1 of 10] 2014/02/17 12:34:15:689 IST [DEBUG] ManagedNHttpClientConnectionImpl - http-outgoing-0 10.0.0.2:58623-93.184.221.133:80[ACTIVE][r:]: Set attribute http.nio.exchange-handler 2014/02/17 12:34:15:690 IST [DEBUG] ManagedNHttpClientConnectionImpl - http-outgoing-0 10.0.0.2:58623-93.184.221.133:80[ACTIVE][rw:]: Event set [w] 2014/02/17 12:34:15:691 IST [DEBUG] ManagedNHttpClientConnectionImpl - http-outgoing-0 10.0.0.2:58623-93.184.221.133:80[ACTIVE][rw:]: Set attribute http.nio.http-exchange-state 2014/02/17 12:34:15:692 IST [DEBUG] ManagedNHttpClientConnectionImpl - http-outgoing-0 10.0.0.2:58623-93.184.221.133:80[ACTIVE][rw:]: Event set [w] 2014/02/17 12:34:15:694 IST [DEBUG] ManagedNHttpClientConnectionImpl - http-outgoing-0 10.0.0.2:58623-93.184.221.133:80[ACTIVE][rw:w]: 246 bytes written 2014/02/17 12:34:15:694 IST [DEBUG] ManagedNHttpClientConnectionImpl - http-outgoing-0 10.0.0.2:58623-93.184.221.133:80[ACTIVE][r:w]: Event cleared [w] 2014/02/17 12:34:15:770 IST [DEBUG] ManagedNHttpClientConnectionImpl - http-outgoing-0 10.0.0.2:58623-93.184.221.133:80[ACTIVE][r:r]: 1360 bytes read 2014/02/17 12:34:15:775 IST [DEBUG] ManagedNHttpClientConnectionImpl - http-outgoing-0 10.0.0.2:58623-93.184.221.133:80[ACTIVE][r:r]: Shutdown 2014/02/17 12:34:17:695 IST [DEBUG] PoolingNHttpClientConnectionManager - Connection request: [route: {}-http://966b.http.dal05.cdn.softlayer.net:80][total kept alive: 0; route allocated: 1 of 1; total allocated: 1 of 10] Note that the last log of “Connection request” reports that “route allocated: 1 of 1”. Doesn’t it mean that the connection was not released when the channel was shut down? It probably does. Please raise a JIRA for this issue. Oleg - To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org For additional commands, e-mail: httpclient-users-h...@hc.apache.org
How can I abort an aynsc request using HttpAsyncClient
Hi I would like to use HttpAsyncClient in order to execute async requests. Is it possible to abort an executing request from another thread? Thanks, -- Yoram Dayagi (Gmail) Sent with Airmail