You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Francois-Xavier Bonnet (JIRA)" <ji...@apache.org> on 2012/12/17 15:12:23 UTC

[jira] [Commented] (HTTPCLIENT-1280) CachingExec catches SocketTimeoutException silently and closes the backend InputStream

    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1280?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13533934#comment-13533934 ] 

Francois-Xavier Bonnet commented on HTTPCLIENT-1280:
----------------------------------------------------

Here is a broken test:

    @Test
    public void testSocketTimeoutExceptionIsNotSilentlyCatched() throws Exception {
        impl = new CachingExec(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
        Date now = new Date();

        HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com"));
        
        final AtomicBoolean inputStreamIsClosed = new AtomicBoolean(false);

        HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
		resp1.setEntity(new InputStreamEntity(new InputStream() {
			private boolean closed = false;
			@Override
		    public void close() throws IOException {
				closed = true;
			}
			@Override
			public int read() throws IOException {
				if(closed)
					throw new SocketException("Socket closed");
				throw new SocketTimeoutException("Read timed out");
			}
		}, 128));
        resp1.setHeader("Date", DateUtils.formatDate(now));

        backendExpectsAnyRequestAndReturn(resp1);

        replayMocks();
        HttpResponse result1 = impl.execute(route, req1);
        
        Assert.assertEquals(HttpStatus.SC_OK, result1.getStatusLine().getStatusCode());
        try {
        	EntityUtils.toString(result1.getEntity());
            Assert.fail("We should have had a SocketTimeoutException");
        } catch (SocketTimeoutException e){
        	Assert.assertTrue("EntityUtils should have closed the InputStream",inputStreamIsClosed.get());
        }

    }

                
> CachingExec catches SocketTimeoutException silently and closes the backend InputStream
> --------------------------------------------------------------------------------------
>
>                 Key: HTTPCLIENT-1280
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1280
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: Cache
>    Affects Versions: 4.2.2, 4.2.3, Snapshot
>            Reporter: Francois-Xavier Bonnet
>
> When a SocketTimeoutException occurs, CachingExec catches and logs it, then closes the Inputstream:
> 11-12 08:23:18 10010 [qtp907773188-11] WARN org.apache.http.impl.client.cache.CachingHttpClient - Unable to store entries in cache
> java.net.SocketTimeoutException: Read timed out
>     at java.net.SocketInputStream.socketRead0(Native Method)
>     at java.net.SocketInputStream.read(SocketInputStream.java:150)
>     at java.net.SocketInputStream.read(SocketInputStream.java:121)
>     at org.apache.http.impl.io.AbstractSessionInputBuffer.read(AbstractSessionInputBuffer.java:204)
>     at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:177)
>     at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:201)
>     at org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:155)
>     at org.apache.http.impl.client.cache.HeapResourceFactory.generate(HeapResourceFactory.java:54)
>     at org.apache.http.impl.client.cache.SizeLimitedResponseReader.doConsume(SizeLimitedResponseReader.java:103)
>     at org.apache.http.impl.client.cache.SizeLimitedResponseReader.readResponse(SizeLimitedResponseReader.java:75)
>     at org.apache.http.impl.client.cache.BasicHttpCache.cacheAndReturnResponse(BasicHttpCache.java:241)
>     at org.apache.http.impl.client.cache.CachingHttpClient.handleBackendResponse(CachingHttpClient.java:916)
>     at org.apache.http.impl.client.cache.CachingHttpClient.callBackend(CachingHttpClient.java:729)
>     at org.apache.http.impl.client.cache.CachingHttpClient.handleCacheMiss(CachingHttpClient.java:508)
>     at org.apache.http.impl.client.cache.CachingHttpClient.execute(CachingHttpClient.java:436)
>     at org.esigate.cache.CacheAdapter$HttpClientWrapper.execute(CacheAdapter.java:123)
> Then there is no way for the code to know that a problem occurred and if you try to read the entity you get another Exception:
> java.net.SocketException: Socket closed
>     at java.net.SocketInputStream.socketRead0(Native Method)
>     at java.net.SocketInputStream.read(SocketInputStream.java:150)
>     at java.net.SocketInputStream.read(SocketInputStream.java:121)
>     at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:166)
>     at org.apache.http.impl.io.SocketInputBuffer.fillBuffer(SocketInputBuffer.java:90)
>     at org.apache.http.impl.io.AbstractSessionInputBuffer.read(AbstractSessionInputBuffer.java:183)
>     at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:140)
>     at org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:121)

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

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