GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — src: fix external memory usage going negative · nodejs/node@75a9192

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src
    • node_crypto.h
  • test/parallel
    • test-gc-tls-external-memory.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/node_crypto.h‎

Copy file name to clipboardExpand all lines: src/node_crypto.h
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,9 @@ class SecureContext : public BaseObject {
198198
}
199199

200200
inline void Reset() {
201-
env()->isolate()->AdjustAmountOfExternalAllocatedMemory(-kExternalSize);
201+
if (ctx_ != nullptr) {
202+
env()->isolate()->AdjustAmountOfExternalAllocatedMemory(-kExternalSize);
203+
}
202204
ctx_.reset();
203205
cert_.reset();
204206
issuer_.reset();
Collapse file

‎test/parallel/test-gc-tls-external-memory.js‎

Copy file name to clipboard
+35Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'use strict';
2+
// Flags: --expose-gc
3+
4+
// Tests that memoryUsage().external doesn't go negative
5+
// when a lot tls connections are opened and closed
6+
7+
const common = require('../common');
8+
if (!common.hasCrypto)
9+
common.skip('missing crypto');
10+
11+
const assert = require('assert');
12+
const net = require('net');
13+
const tls = require('tls');
14+
15+
// Payload doesn't matter. We just need to have the tls
16+
// connection try and connect somewhere.
17+
const yolo = Buffer.alloc(10000).fill('yolo');
18+
const server = net.createServer(function(socket) {
19+
socket.write(yolo);
20+
});
21+
22+
server.listen(0, common.mustCall(function() {
23+
const { port } = server.address();
24+
let runs = 0;
25+
connect();
26+
27+
function connect() {
28+
global.gc();
29+
assert(process.memoryUsage().external >= 0);
30+
if (runs++ < 512)
31+
tls.connect(port).on('error', connect);
32+
else
33+
server.close();
34+
}
35+
}));

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.