-
Notifications
You must be signed in to change notification settings - Fork 539
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: socket back pressure memory leak
Fixes: #434
- Loading branch information
Showing
2 changed files
with
65 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
'use strict' | ||
|
||
const { Client } = require('..') | ||
const { createServer } = require('http') | ||
const { Readable } = require('stream') | ||
const { test } = require('tap') | ||
|
||
test('socket back-pressure', (t) => { | ||
t.plan(2) | ||
|
||
const server = createServer() | ||
|
||
let body | ||
|
||
server.on('request', (req, res) => { | ||
let bytesWritten = 0 | ||
const buf = Buffer.allocUnsafe(16384) | ||
new Readable({ | ||
read () { | ||
bytesWritten += buf.length | ||
this.push(buf) | ||
if (bytesWritten >= 1e6) { | ||
this.push(null) | ||
} | ||
} | ||
}).on('end', () => { | ||
t.ok(body._readableState.length < body._readableState.highWaterMark) | ||
}).pipe(res) | ||
}) | ||
|
||
server.listen(0, () => { | ||
const client = new Client(`http://localhost:${server.address().port}`, { | ||
pipelining: 1 | ||
}) | ||
|
||
client.request({ path: '/', method: 'GET', opaque: 'asd' }, (err, data) => { | ||
t.error(err) | ||
body = data.body | ||
.resume() | ||
.on('data', () => { | ||
data.body.pause() | ||
}) | ||
}) | ||
}) | ||
}) |