|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
SO_TIMEOUT on a request levelHi,
The scenario is as follows: I'm doing two consecutive requests to the same host, using a multi-threaded (or thread safe) connection pool manager. The first invocation has a timeout of 10s and the second has a timeout of 30s. In version 3.1 of HttpClient all works well, but in 4.0 I get a timeout exception in the second request, after ~10 seconds, which means the first timeout is used. Looking at the code, I see that in version 3.1, the HttpMethodDirector.executeWithRetry() method invokes a method named applyConnectionParams() that took care of setting the timeout taken from the request on the socket. But in version 4.0, the only place I see the timeout is set on the socket is when DefaultRequestDirector.execute(HttpHost, HttpRequest, HttpContext) opens a connection using the managedConn.open() method. Since the connection is reused between the requests, the second request uses a socket with a timeout of the first request. As a (bad) workaround, I put on the HttpClient instance a ConnectionReuseStrategy that always says no to reusing the connection, so a new connection is created for the second request, with the required timeout. Am I missing something? Thanks, Moshe. The information contained in this message is proprietary to the sender, protected from disclosure, and may be privileged. The information is intended to be conveyed only to the designated recipient(s) of the message. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, use, distribution or copying of this communication is strictly prohibited and may be unlawful. If you have received this communication in error, please notify us immediately by replying to the message and deleting it from your computer. Thank you. ************************************************************************************ This footnote confirms that this email message has been scanned by PineApp Mail-SeCure for the presence of malicious code, vandals & computer viruses. ************************************************************************************ |
|
|
Re: SO_TIMEOUT on a request levelMoshe Ben-Shoham wrote:
> Hi, > > > > The scenario is as follows: I'm doing two consecutive requests to the > same host, using a multi-threaded (or thread safe) connection pool > manager. The first invocation has a timeout of 10s and the second has a > timeout of 30s. > > > > In version 3.1 of HttpClient all works well, but in 4.0 I get a timeout > exception in the second request, after ~10 seconds, which means the > first timeout is used. > > > > Looking at the code, I see that in version 3.1, the > HttpMethodDirector.executeWithRetry() method invokes a method named > applyConnectionParams() that took care of setting the timeout taken from > the request on the socket. > > > > But in version 4.0, the only place I see the timeout is set on the > socket is when DefaultRequestDirector.execute(HttpHost, HttpRequest, > HttpContext) opens a connection using the managedConn.open() method. > Since the connection is reused between the requests, the second request > uses a socket with a timeout of the first request. As a (bad) > workaround, I put on the HttpClient instance a ConnectionReuseStrategy > that always says no to reusing the connection, so a new connection is > created for the second request, with the required timeout. > > > > Am I missing something? > > > > Thanks, > > Moshe. > Hi Moshe This is definitely a bug. Please raise a JIRA for this issue: https://issues.apache.org/jira/browse/HTTPCLIENT As a somewhat cleaner workaround you can obtain the actual connection from the execution context and reset the timeout on that connection. This at least will work for the response body. --- DefaultHttpClient httpclient = new DefaultHttpClient(); HttpGet request = new HttpGet("http://www.google.com/"); HttpContext context = new BasicHttpContext(); HttpResponse rsp = httpclient.execute(request, context); HttpClientConnection conn = (HttpClientConnection) context.getAttribute( ExecutionContext.HTTP_CONNECTION); conn.setSocketTimeout(1000); HttpEntity entity = rsp.getEntity(); System.out.println("----------------------------------------"); System.out.println(rsp.getStatusLine()); System.out.println("----------------------------------------"); if (entity != null) { entity.consumeContent(); } --- Oleg --------------------------------------------------------------------- To unsubscribe, e-mail: httpclient-users-unsubscribe@... For additional commands, e-mail: httpclient-users-help@... |
| Free embeddable forum powered by Nabble | Forum Help |