| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3cec988 commit 75a9192
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -198,7 +198,9 @@ class SecureContext : public BaseObject { | |||
| 198 | 198 | } | |
| 199 | 199 | ||
| 200 | 200 | inline void Reset() { | |
| 201 | - env()->isolate()->AdjustAmountOfExternalAllocatedMemory(-kExternalSize); | ||
| 201 | + if (ctx_ != nullptr) { | ||
| 202 | + env()->isolate()->AdjustAmountOfExternalAllocatedMemory(-kExternalSize); | ||
| 203 | + } | ||
| 202 | 204 | ctx_.reset(); | |
| 203 | 205 | cert_.reset(); | |
| 204 | 206 | issuer_.reset(); | |
| Original file line number | Diff line number | Diff 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 | + })); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments