-
Notifications
You must be signed in to change notification settings - Fork 9.2k
HADOOP-18383. Codecs with @DoNotPool annotation are not closed causing memory leak #4585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
43a3b58
032209a
a708608
b6ed11c
74e2a97
c6e9bc2
c44808b
622e5fd
5200470
ca8dfc3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,14 +18,23 @@ | |
| package org.apache.hadoop.io.compress; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.fail; | ||
|
|
||
| import java.io.ByteArrayInputStream; | ||
| import java.io.ByteArrayOutputStream; | ||
| import java.io.IOException; | ||
| import java.io.OutputStream; | ||
| import java.util.Random; | ||
| import java.util.concurrent.Callable; | ||
| import java.util.concurrent.ExecutorService; | ||
| import java.util.concurrent.Executors; | ||
| import java.util.concurrent.LinkedBlockingDeque; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.io.compress.zlib.BuiltInGzipCompressor; | ||
| import org.apache.hadoop.io.compress.zlib.BuiltInGzipDecompressor; | ||
| import org.junit.Assert; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
|
|
||
|
|
@@ -189,4 +198,54 @@ public void testDecompressorNotReturnSameInstance() { | |
| CodecPool.returnDecompressor(decompressor); | ||
| } | ||
| } | ||
|
|
||
| @Test(timeout = 10000) | ||
| public void testDoNotPoolCompressorNotUseableAfterReturn() throws IOException { | ||
|
|
||
| final GzipCodec gzipCodec = new GzipCodec(); | ||
| gzipCodec.setConf(new Configuration()); | ||
|
|
||
| // BuiltInGzipCompressor is an explicit example of a Compressor with the @DoNotPool annotation | ||
| final Compressor compressor = new BuiltInGzipCompressor(new Configuration()); | ||
| CodecPool.returnCompressor(compressor); | ||
|
|
||
| try (CompressionOutputStream outputStream = | ||
| gzipCodec.createOutputStream(new ByteArrayOutputStream(), compressor)) { | ||
| outputStream.write(1); | ||
| fail("Compressor from Codec with @DoNotPool should not be useable after returning to CodecPool"); | ||
| } catch (NullPointerException exception) { | ||
|
||
| Assert.assertEquals("Deflater has been closed", exception.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| @Test(timeout = 10000) | ||
| public void testDoNotPoolDecompressorNotUseableAfterReturn() throws IOException { | ||
|
|
||
| final GzipCodec gzipCodec = new GzipCodec(); | ||
| gzipCodec.setConf(new Configuration()); | ||
|
|
||
| final Random random = new Random(); | ||
| final byte[] bytes = new byte[1024]; | ||
| random.nextBytes(bytes); | ||
|
|
||
| ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||
| try (OutputStream outputStream = gzipCodec.createOutputStream(baos)) { | ||
| outputStream.write(bytes); | ||
| } | ||
|
|
||
| final byte[] gzipBytes = baos.toByteArray(); | ||
| final ByteArrayInputStream bais = new ByteArrayInputStream(gzipBytes); | ||
|
|
||
| // BuiltInGzipDecompressor is an explicit example of a Decompressor with the @DoNotPool annotation | ||
| final Decompressor decompressor = new BuiltInGzipDecompressor(); | ||
| CodecPool.returnDecompressor(decompressor); | ||
|
|
||
| try (CompressionInputStream inputStream = | ||
goiri marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| gzipCodec.createInputStream(bais, decompressor)) { | ||
| inputStream.read(); | ||
| fail("Decompressor from Codec with @DoNotPool should not be useable after returning to CodecPool"); | ||
| } catch (NullPointerException exception) { | ||
| Assert.assertEquals("Inflater has been closed", exception.getMessage()); | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.