To clarify a bit what I'm trying to achieve here...
Suppose when in the service which reads from a file, fills a buffer and then instructs netty to send it over the network I write something like:
while (<ther are buffers available>) {
<get byteBuffer>
ChannelFuture channelFuture = ctx.channel().writeAndFlush(byteBuffer);
channelFuture.await();}
This will mean that untill the current buffer is not physically sent over the network, netty will not try to send anything else. It work nice and clean, sending 3Gb file without any problems.
However, suppose I want to obtain a bunch of buffers at once, and schedule them for sending. How do I specify how much data netty can accumulate before it can accept no more and block?
Right now if I try to send a big file like this:
while (<ther are buffers available>) {
<get byteBuffer>
ctx.channel().writeAndFlush(byteBuffer); } // do not wait for the current buffer to be physically written
I quickly get OutOfMemory error and direct buffers occupy all the available memory.
Btw, all my inbound handlers extend SimpleChannelInboundHandler, and release byteBufs automatically. Also, I do not see any leaks reported by ResourceLeakDetector.