stream: unshift('') is a noop
authorisaacs <i@izs.me>
Mon, 3 Jun 2013 17:50:02 +0000 (10:50 -0700)
committerisaacs <i@izs.me>
Mon, 3 Jun 2013 17:50:04 +0000 (10:50 -0700)
commitdf6ffc018ef0d166486d1323412472b981ecb648
treebe65cae97327ccad3863dda20716eb5edc7e962a
parentce54f4ae50a5bd224e08bf058b118a7c68966cb4
stream: unshift('') is a noop

In some cases, the http CONNECT/Upgrade API is unshifting an empty
bodyHead buffer onto the socket.

Normally, stream.unshift(chunk) does not set state.reading=false.
However, this check was not being done for the case when the chunk was
empty (either `''` or `Buffer(0)`), and as a result, it was causing the
socket to think that a read had completed, and to stop providing data.

This bug is not limited to http or web sockets, but rather would affect
any parser that unshifts data back onto the source stream without being
very careful to never unshift an empty chunk.  Since the intent of
unshift is to *not* change the state.reading property, this is a bug.

Fixes #5557
Fixes LearnBoost/socket.io#1242
lib/_stream_readable.js
test/simple/test-stream-unshift-empty-chunk.js [new file with mode: 0644]