Skip to content
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

Potential out of memory error if writing too fast and having slow receiver #881

Open
xiazuojie opened this issue Oct 30, 2019 · 2 comments
Labels
type/bug A general bug

Comments

@xiazuojie
Copy link

xiazuojie commented Oct 30, 2019

Currently the code does not check whether channel is writable before invoking ChannelHandlerContext.write(). Instead, it checks whether channel is writable after writing to it, and flushes the channel in case it's not writable.

In the case of writing fast and having slow receiver, flushing may not make a channel writable immediately. However, the code always writes incoming messages to the channel. Messages may pile up in the internal queue of netty, and worse, exhaust memory if the situation (writing fast and having slow receiver) never changes.

Expected Behavior

No out of memory error when having slow receivers.

Actual Behavior

Messages piles up in the internal queue of netty, and worse, exhausts memory if the situation (writing fast and having slow receiver) never changes

Steps to Reproduce

Possible Solution

Need to check whether channel is writable (buffer not full) before writing to it. In case it's not writable, discard new messages with an error.

Your Environment

  • Reactor version(s) used:0.8.9
  • Other relevant libraries versions (eg. netty, ...):rsocket-java
  • JVM version (javar -version):java version "1.8.0_101"
  • OS and version (eg uname -a):Darwin *** 19.0.0 Darwin Kernel Version 19.0.0: Wed Sep 25 20:18:50 PDT 2019; root:xnu-6153.11.26~2/RELEASE_X86_64 x86_64
@xiazuojie xiazuojie added status/need-triage A new issue that still need to be evaluated as a whole type/bug A general bug labels Oct 30, 2019
@violetagg violetagg removed the status/need-triage A new issue that still need to be evaluated as a whole label Jan 13, 2020
@violetagg violetagg added this to the 0.9.x Maintenance Backlog milestone Jan 13, 2020
@violetagg violetagg modified the milestones: 0.9.x Maintenance Backlog, 1.0.x Backlog Jan 18, 2021
@ctlove0523
Copy link
Contributor

@xiazuojie
can you support a simple demo to reproduce this issue?

@xiazuojie
Copy link
Author

xiazuojie commented Apr 28, 2021

You can emulate this by pausing (through debug) the receiver process while the sender continues writing messages. The sender will be out of memory eventually.

It's a pitfall warned by Norman Maurer (one of the core developers of Netty) here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants