indutny/node-spdy — pull request #175 by ploer (2014-09-26 20:44:46+00:00)
Title: create backpressure on socket write buffering

See issue #174 for details of the issue this addresses.

This change addresses the issue in my test environment, and node-spdyproxy seems stable with the change under both 0.10.x and 0.8.x.

Tests are failing under 0.8.x but it looks like that is not due to my change (latest travis run on master branch also failed 0.8.x on the same cases).

The change in _writeData is somewhat duplicative with the window exhaustion check immediately below, but it seemed clearer to me to express the two checks separately. Happy to combine them or factor into a function if you prefer.

On socket 'drain' event, each stream's `_drainSink()` is called unconditionally. Presumably this could happen while there are buffered writes in the sink due to the window being exhausted, and so it would be inappropriate to do any new writes, but the drainSink mechanism should deal with this fine by just re-buffering them if they are not ready. Simplicity seemed preferable to trying to prematurely optimize that away, but if you see a performance concern (possibly with a writer who is buffering very large amounts into the spdy code?), that could be easily changed, maybe just with an early exit out of `_drainSink()` if either the window is still full or the socket is still buffering.

Let me know what you think.

Thanks!