File tree Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Original file line number Diff line number Diff 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 ();
Original file line number Diff line number Diff line change 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+ } ) ) ;
You can’t perform that action at this time.
0 commit comments