joyent/node — pull request #4968 by isaacs (2013-03-09 18:57:29+00:00)
Title: stream: Avoid nextTick warning filling read buffer

In the function that pre-emptively fills the Readable queue, it
relies on a recursion through:

stream.push(chunk) ->
maybeReadMore(stream, state) ->
if (not reading more and < hwm) stream.read(0) ->
stream._read() ->
stream.push(chunk) -> repeat.

Since this was only calling read() a single time, and then relying
on a future nextTick to collect more data, it ends up causing a nextTick
recursion error (and potentially a RangeError, even) if you have a very
high highWaterMark, and are getting very small chunks pushed synchronously
in _read (as happens with TLS, or many simple test streams).

This change implements a new approach, so that read(0) is called repeatedly
as long as it is effective (that is, the length keeps increasing), and thus
quickly fills up the buffer for streams such as these, without any stacks
overflowing.