-
Notifications
You must be signed in to change notification settings - Fork 7.3k
No 'readable' events after unshift-ing more than highWaterMark bytes #7678
Comments
@pepagos what is the purpose of removing and re-adding the |
It is explained in the issue. |
@pepagos sorry, I've lost all context from when I asked that question. I have a local branch where I was working on a test and fix and wanted to confirm the use-case, but the state of where I was is now a mystery to me. |
@pepagos ... is this still an issue for you? can you test the latest v0.12.x and io.js? |
Tested with node-v0.12.5 and iojs-v2.3.1. |
Possibly related to #14604. Calling |
Removing a readable listener now updates the readable state i.e. readableListening, needReadable and emittedReadable are set to false. Then, if a readable listener is added at a later time, the stream will know none are attached and will take proper action to get the stream going back again. Fixes nodejs#7678
After investigating, I found that the problem actually was related to removing and adding a listener to readable, unshifting in-between. Basically, removing a readable listener doesn't update readableListening state - it remains true. Unshifting then puts data back into the stream, and emits a readable... but no one is there to catch it. Then, when you re-attach a readable listener, the stream code goes right through and doesn't check to see if it should emit a readable event (or call a You didn't get any error when toUnshift < 16 * 1024 (the highWaterMark) because that would make the internal push call from the socket to the stream return true; the socket then wouldn't stop reading from the event loop. You would then add your readable listener back again, and move on. On the other hand, when toUnshift >= 16 * 1024, push would return false, the socket would stop reading from the event loop, and adding the readable listener back again would not trigger a _read... causing the program to hang. I submitted a PR which solves this issue. |
readableListening, needReadable and emittedReadable are set to false. Then, if a readable listener is added at a later time, the stream will know none are attached and will take proper action to get the stream going back again. Fixes nodejs#7678
readableListening, needReadable and emittedReadable are set to false. Then, if a readable listener is added at a later time, the stream will know none are attached and will take proper action to get the stream going back again. Fixes nodejs/node-v0.x-archive#7678
In the following test, if toUnshift is less than 16_1024, the program writes messages without end, as pretended.
But if toUnshift is greater than or equal to 16_1024, the program stops after the first 'readable' event.
This program is the simplest I could write to exhibit this strange behaviour.
It occurred to me in a real program that accepts several protocols in the same port; these protocols can be optionally compressed and encrypted with ssl.
The program explores the first bytes to determine the protocol, unshifts the read data and jumps to the found protocol.
The text was updated successfully, but these errors were encountered: