azure-sdk-for-java: [BUG] OutOfMemoryError: Direct buffer memory when uploading large file

Describe the bug When I’m trying to upload file much bigger than heap to blob storage size I’m getting OutOfMemoryError

Exception or Stack Trace

Operator called default onErrorDropped
java.lang.IllegalStateException: java.lang.OutOfMemoryError: Direct buffer memory
	at io.netty.channel.AbstractCoalescingBufferQueue.releaseAndCompleteAll(AbstractCoalescingBufferQueue.java:351)
	at io.netty.channel.AbstractCoalescingBufferQueue.releaseAndFailAll(AbstractCoalescingBufferQueue.java:207)
	at io.netty.handler.ssl.SslHandler.releaseAndFailAll(SslHandler.java:1814)
	at io.netty.handler.ssl.SslHandler.setHandshakeFailure(SslHandler.java:1793)
	at io.netty.handler.ssl.SslHandler.setHandshakeFailure(SslHandler.java:1757)
	at io.netty.handler.ssl.SslHandler.flush(SslHandler.java:775)
	at io.netty.channel.AbstractChannelHandlerContext.invokeFlush0(AbstractChannelHandlerContext.java:748)
	at io.netty.channel.AbstractChannelHandlerContext.invokeFlush(AbstractChannelHandlerContext.java:740)
	at io.netty.channel.AbstractChannelHandlerContext.flush(AbstractChannelHandlerContext.java:726)
	at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.flush(CombinedChannelDuplexHandler.java:531)
	at io.netty.channel.ChannelOutboundHandlerAdapter.flush(ChannelOutboundHandlerAdapter.java:125)
	at io.netty.channel.CombinedChannelDuplexHandler.flush(CombinedChannelDuplexHandler.java:356)
	at io.netty.channel.AbstractChannelHandlerContext.invokeFlush0(AbstractChannelHandlerContext.java:748)
	at io.netty.channel.AbstractChannelHandlerContext.invokeFlush(AbstractChannelHandlerContext.java:740)
	at io.netty.channel.AbstractChannelHandlerContext.flush(AbstractChannelHandlerContext.java:726)
	at reactor.netty.channel.MonoSendMany$SendManyInner.run(MonoSendMany.java:296)
	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500)
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.OutOfMemoryError: Direct buffer memory
	at java.base/java.nio.Bits.reserveMemory(Bits.java:175)
	at java.base/java.nio.DirectByteBuffer.<init>(DirectByteBuffer.java:118)
	at java.base/java.nio.ByteBuffer.allocateDirect(ByteBuffer.java:317)
	at io.netty.buffer.PoolArena$DirectArena.allocateDirect(PoolArena.java:758)
	at io.netty.buffer.PoolArena$DirectArena.newChunk(PoolArena.java:734)
	at io.netty.buffer.PoolArena.allocateNormal(PoolArena.java:245)
	at io.netty.buffer.PoolArena.allocate(PoolArena.java:227)
	at io.netty.buffer.PoolArena.allocate(PoolArena.java:147)
	at io.netty.buffer.PooledByteBufAllocator.newDirectBuffer(PooledByteBufAllocator.java:342)
	at io.netty.buffer.AbstractByteBufAllocator.directBuffer(AbstractByteBufAllocator.java:187)
	at io.netty.buffer.AbstractByteBufAllocator.directBuffer(AbstractByteBufAllocator.java:178)
	at io.netty.handler.ssl.SslHandler$SslEngineType$1.allocateWrapBuffer(SslHandler.java:215)
	at io.netty.handler.ssl.SslHandler.allocateOutNetBuf(SslHandler.java:2145)
	at io.netty.handler.ssl.SslHandler.wrap(SslHandler.java:821)
	at io.netty.handler.ssl.SslHandler.wrapAndFlush(SslHandler.java:792)
	at io.netty.handler.ssl.SslHandler.flush(SslHandler.java:773)
	... 17 more

To Reproduce Steps to reproduce the behavior:

Code Snippet

azure.getBlobClient(blobName).uploadFromFile(absolutePath, overwrite)

Expected behavior Do not fail with error

Setup (please complete the following information):

  • OS: Windows, Linux, Mac OS X
  • IDE : IntelliJ
  • Version of the Library used: 12.6.1

Additional context I have bunch of another reports/questions because I have very special setup: I’m developing plugin for IDE, so my files are being loaded with another classloader (which is not even URLClassloader) and also it works inside IDE so potentially strange side-effects may occure.

Information Checklist Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

  • Bug Description Added
  • Repro Steps Added
  • Setup information Added

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 44 (22 by maintainers)

Most upvoted comments

Makes sense to me! Thank you for giving it a test! I am going to close this issue since I believe it has been resolved. The fix is in master and will go out with our GA release this week or next.