hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Francois-Xavier Bonnet (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (HTTPCLIENT-1281) GzipDecompressingEntity does not release InputStream when an IOException occurs while reading the Gzip header
Date Fri, 21 Dec 2012 08:51:13 GMT

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

Francois-Xavier Bonnet commented on HTTPCLIENT-1281:

> You see, this would create certain ambiguity as whether one must call #close on input
stream returned by the #getCcontent method, #release method or both.

I think the confusion is already here. When using an entity, do I have to close the input
stream from #getContent method, call EntityUtils.consume(HttpEntity) or both or does the answer
depends on the kind of Entity (repeatable?, streaming?). Maybe this is why we had this bug.
In addition, for a HttpClient beginner, there is nothing obvious in HttpEntity interface that
tells me that I have to release something (some method named like close or dispose or release).
Many people forget to release resources in their first attempts to use HttpClient.

> More importantly, though, we cannot change HttpEntity interface as long as we do not
want to start the 5.x development cycle and start breaking API compatibility.


> (1) always close response regardless of its status code

You mean EntityUtils.consume(HttpEntity) or something else ?

> GzipDecompressingEntity does not release InputStream when an IOException occurs while
reading the Gzip header
> -------------------------------------------------------------------------------------------------------------
>                 Key: HTTPCLIENT-1281
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1281
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient
>    Affects Versions: 4.2.2, 4.2.3, Snapshot
>            Reporter: Francois-Xavier Bonnet
>            Priority: Blocker
>             Fix For: 4.2.3
>         Attachments: DecompressingEntity_patch.txt
> When calling method org.apache.http.client.entity.DecompressingEntity.getContent() for
a GzipDecompressingEntity, the method tries to build a GZIPInputStream, then the GzipInputStream
tries to read the Gzip header and fails throwing an IOException.
> At the end you get an Exception but the backend InputStream is never closed resulting
in a connection leak.
> Here is a test to reproduce:
> 	@Test
> 	public void testGzipDecompressingEntityDoesNotCrashInConstructorAndLeaveInputStreamOpen()
> 			throws Exception {
> 		final AtomicBoolean inputStreamIsClosed = new AtomicBoolean(false);
> 		HttpEntity in = new InputStreamEntity(new InputStream() {
> 			@Override
> 			public int read() throws IOException {
> 				throw new IOException("An exception occurred");
> 			}
> 			@Override
> 			public void close() throws IOException {
> 				inputStreamIsClosed.set(true);
> 			}
> 		}, 123);
> 		GzipDecompressingEntity gunzipe = new GzipDecompressingEntity(in);
> 		try {
> 			InputStream is = gunzipe.getContent();
> 		} catch (IOException e) {
> 			// As I cannot get the content, GzipDecompressingEntity is supposed
> 			// to have released everything
> 			Assert.assertTrue(inputStreamIsClosed.get());
> 		}
> 	}

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

View raw message