Skip to content

NioSocketChannel$WriteRequestQueue has no limit and is causing OutOfMemory #574

Closed

Description

@rpelissier

I am using Netty to perform large file upload. It works fine but the RAM used by the client seems to increase with the size of the file. This is not the expected behaviour since everything is piped from the Reading the source file to writing the target file.

At first, I thought about a kind of adaptive buffer growing up until Xmx is reached but setting Xmx to a reasonable value (50M) would lead to an OutOfMemoryError soon after starting upload. After some research using Eclipse Memory Analyzer, it appears that the object retaining the heap memory is:

org.jboss.netty.channel.socket.nio.NioSocketChannel$WriteRequestQueue

Is this the expected behaviour, is there any option for setting a limit to this queue or do I have to code my own queue using ChannelFutures to control the number of bytes and block the pipe when the limit is reached?

Thanks for your help,

Regards,

Renaud

Activity

  1. normanmaurer commented on Aug 29, 2012

    @normanmaurer
    Member

    @rpelissier you should use Channel.isWritable() to check if the "queue" is full. If so you will need to check if there is enough space to write more. So the effect you see can happen if you write data to quickly to get it send out to the clients.
    You can get around this kind of problems when try to write a File via DefaultFileRegion or ChunkedFile.

  2. rpelissier commented on Aug 29, 2012

    @rpelissier
    Author

    @normanmaurer thank you I missed this method of the Channel!
    I guess I need to read what's happening inside:

    org.jboss.netty.handler.stream.ChunkedWriteHandler
  3. added a commit that references this issue on Apr 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions