Skip to content

Commit

Permalink
Actually emit drain when backpressure kicks in (#329)
Browse files Browse the repository at this point in the history
Signed-off-by: Matteo Collina <[email protected]>
  • Loading branch information
mcollina authored Jan 8, 2025
1 parent 2513cdf commit bae8423
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ function Response (req, onEnd, reject) {
http.ServerResponse.call(this, req)

if (req._lightMyRequest?.payloadAsStream) {
this._lightMyRequest = { headers: null, trailers: {}, stream: new Readable({ read () {} }) }
const read = this.emit.bind(this, 'drain')
this._lightMyRequest = { headers: null, trailers: {}, stream: new Readable({ read }) }
const signal = req._lightMyRequest.signal

if (signal) {
Expand Down
4 changes: 3 additions & 1 deletion test/stream.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ test('stream mode - backpressure', (t, done) => {
const buf = Buffer.alloc(1024 * 1024).fill('b')
t.assert.strictEqual(res.write(buf), false)
expected = 'a' + buf.toString()
res.end()
res.on('drain', () => {
res.end()
})
}

inject(dispatch, { method: 'GET', url: '/', payloadAsStream: true }, (err, res) => {
Expand Down

0 comments on commit bae8423

Please sign in to comment.