-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src: fix external memory usage going negative
PR-URL: #22594 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
- Loading branch information
Showing
2 changed files
with
38 additions
and
1 deletion.
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,35 @@ | ||
'use strict'; | ||
// Flags: --expose-gc | ||
|
||
// Tests that memoryUsage().external doesn't go negative | ||
// when a lot tls connections are opened and closed | ||
|
||
const common = require('../common'); | ||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
|
||
const assert = require('assert'); | ||
const net = require('net'); | ||
const tls = require('tls'); | ||
|
||
// Payload doesn't matter. We just need to have the tls | ||
// connection try and connect somewhere. | ||
const yolo = Buffer.alloc(10000).fill('yolo'); | ||
const server = net.createServer(function(socket) { | ||
socket.write(yolo); | ||
}); | ||
|
||
server.listen(0, common.mustCall(function() { | ||
const { port } = server.address(); | ||
let runs = 0; | ||
connect(); | ||
|
||
function connect() { | ||
global.gc(); | ||
assert(process.memoryUsage().external >= 0); | ||
if (runs++ < 512) | ||
tls.connect(port).on('error', connect); | ||
else | ||
server.close(); | ||
} | ||
})); |