Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

streams2 push and high water marks #4814

Closed
Raynos opened this issue Feb 21, 2013 · 1 comment
Closed

streams2 push and high water marks #4814

Raynos opened this issue Feb 21, 2013 · 1 comment

Comments

@Raynos
Copy link

Raynos commented Feb 21, 2013

When you call stream.push(data) it will return true indicating push more data in if the needReadable flag is set. This holds true even if we are above the high water mark. This can lead to the stream being filled above the high water mark pulling too much data into memory

consider the following gist

I expect the example below to indicate me that I should stop pushing data into this stream.

var Readable = require('stream').Readable
var assert = require('assert')

var count = 100
var list = []
for (var i = 0; i < count; i++) {
    list.push(i)
}

var s = Readable({
    objectMode: true
    , highWaterMark: 100
})

s._read = function () {
    var bools = list.map(function (i) {
        return s.push(i)
    })

    assert.ok(bools.every(function (x) {
        return x === true
    }))

    var needMore = s.push(100)
    // IS ACTUALLY TRUE because s.needReadable is set
    // I think if push makes it go over the high water mark we should
    // return false and ignore the fact we need a readable.
    assert.equal(needMore, false)

    // console.log("s", s._readableState)
}

s.read(0)
@isaacs
Copy link

isaacs commented Feb 23, 2013

Fixed on master.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants