spdy-http2 / node-spdy

SPDY server on Node.js
2.81k stars 196 forks source link

slow clients don't appear to be creating backpressure #174

Closed ploer closed 10 years ago

ploer commented 10 years ago

I've been doing some node-spdyproxy testing, and have observed that with a Chrome client connecting over a slow connection, the proxy will quickly buffer a full client receive window of 10MB, which the client will then slowly draw down.

This creates a problem in my use case because some web servers will drop a client that doesn't seem to be doing anything for, say, 30 seconds, and in this case, if we quickly buffer up 10MB it may be minutes before the proxy makes the next request to the server.

It looks to me like part of the reason the spdy code is accepting all these writes even though the client is way behind is that the return value from socket.write() in Connection.prototype.write doesn't propagate back up the pipe. In my test scenario I am able to verify that socket.write() quickly starts returning false when dealing with a slow client, but spdy continues to accept writes and send them through to the socket buffer until the client receive window fills up.

So my questions would be (1) am I missing something here, or is that expected current behavior? and, (2) would it make sense to change this to not buffer, or possibly make it an option?

I'm working on a change at https://github.com/ploer/node-spdy/commits/backpressure that appears to address my issue & passes tests at least under 0.10; I'd be happy to develop that into a pull request if it seems like the right direction.

Thanks!

indutny commented 10 years ago

I think it really works as intended right now, but I see the problem that you are describing.

This could be possibly worked around by proxy sending SETTINGS frame to a server to make the input window smaller and stop it from sending more stuff until the actual data will go through the TCP stream.

indutny commented 10 years ago

Ah, I just realized that the other server is most likely not a SPDY server :) Anyway, yeah, I think the patch that will fix the problem would be welcome.

ploer commented 10 years ago

Yes, everything will presumably be simpler in the glorious all-SPDY future. :-)

Ok, great, I'll get that submitted soon. Thanks!