ibc / EventMachine-LE

EventMachine-LE (Live Edition), a "branch" of EventMachine with fixes and more features
http://ibc.github.com/EventMachine-LE
Other
60 stars 12 forks source link

Implement EM::Connection#backpressure_level= to avoid DoS attack #4

Open ibc opened 12 years ago

ibc commented 12 years ago

"EM is reading from the socket as fast as possible and queuing outgoing responses, but the network is actually unable to deliver those responses at the same rate. This causes the internal outbound buffers to grow, thus increasing memory usage."

This is a potential DoS attack.

The proposal is reported in EM tracker: https://github.com/eventmachine/eventmachine/issues/160 And the original issue is also reported there: https://github.com/eventmachine/eventmachine/issues/157

PS: No milestone asigned to this issue as maybe it better to leave it for later than 1.1.0.

ibc commented 12 years ago

I've created a new branch "backpressure_level" to handle this issue.

ibc commented 12 years ago

There is an initial commit within "backpressure_level" branch. For now it adds a "blackpressure_level" attribute to the connection object (in C++) and modifies ConnectionDescriptor::SelectForRead() as follows:

  if (bPaused)
    return false;
  else if (bConnectPending)
    return false;
  else if (bWatchOnly)
    return bNotifyReadable ? true : false;
  // TODO: When this occurs, the connection remains open but it's not closed after comm_inactivity_timeout value.
  // TODO: When this occurs, the connection does not read data anymore.
  // Explanation by Aman: The other edge case this introduces is that dead connections will not be discovered,
  // as the reactor never attempts a read() and thus never realizes that the other end has terminated the connection.
  else if (GetOutboundDataSize() > BackPressureLevel) {
    return false;
  }
  else
    return true;

I don't like the result. It requires more work.