SIZE_CLASSES in 4.2.16 tops out at 16896 bytes. Any allocation above ~16KB
routes to BuddyChunk via ConcurrentSkipListChunkCache. When the cache
exceeds CHUNK_REUSE_QUEUE entries, offerChunk() calls markToDeallocate()
on a chunk that may still have live buffer references — freeing native memory
while AdaptiveByteBufs still point into it → direct memory leak → OOM.
Not present in 4.2.11 (SIZE_CLASSES included 32768 and 65536, shielding BuddyChunk from high traffic).
mvn package -DskipTests mvn dependency:copy-dependencies -DoutputDirectory=target/deps
java -XX:MaxDirectMemorySize=256m \
-cp "target/netty-oom-repro-1.0.jar:target/deps/*" \
com.example.NettyOomReproExpected output:
Netty: 4.2.16.Final
Threads=32 bufSize=1024KB hold=16 iters=5000
Expecting OutOfMemoryError on direct memory...
OOM: Cannot reserve 8388608 bytes of direct buffer memory (allocated: 265289729, limit: 268435456)
...
REPRODUCED: 30 thread(s) hit OOM