File tree Expand file tree Collapse file tree 2 files changed +49
-2
lines changed Expand file tree Collapse file tree 2 files changed +49
-2
lines changed Original file line number Diff line number Diff line change @@ -101,6 +101,19 @@ TLSWrap::~TLSWrap() {
101
101
#ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
102
102
sni_context_.Reset ();
103
103
#endif // SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
104
+
105
+ // See test/parallel/test-tls-transport-destroy-after-own-gc.js:
106
+ // If this TLSWrap is garbage collected, we cannot allow callbacks to be
107
+ // called on this stream.
108
+
109
+ if (stream_ == nullptr )
110
+ return ;
111
+ stream_->set_destruct_cb ({ nullptr , nullptr });
112
+ stream_->set_after_write_cb ({ nullptr , nullptr });
113
+ stream_->set_alloc_cb ({ nullptr , nullptr });
114
+ stream_->set_read_cb ({ nullptr , nullptr });
115
+ stream_->set_destruct_cb ({ nullptr , nullptr });
116
+ stream_->Unconsume ();
104
117
}
105
118
106
119
@@ -564,12 +577,16 @@ uint32_t TLSWrap::UpdateWriteQueueSize(uint32_t write_queue_size) {
564
577
565
578
566
579
int TLSWrap::ReadStart () {
567
- return stream_->ReadStart ();
580
+ if (stream_ != nullptr )
581
+ return stream_->ReadStart ();
582
+ return 0 ;
568
583
}
569
584
570
585
571
586
int TLSWrap::ReadStop () {
572
- return stream_->ReadStop ();
587
+ if (stream_ != nullptr )
588
+ return stream_->ReadStop ();
589
+ return 0 ;
573
590
}
574
591
575
592
Original file line number Diff line number Diff line change
1
+ // Flags: --expose-gc
2
+ 'use strict' ;
3
+
4
+ // Regression test for https://github.com/nodejs/node/issues/17475
5
+ // Unfortunately, this tests only "works" reliably when checked with valgrind or
6
+ // a similar tool.
7
+
8
+ const common = require ( '../common' ) ;
9
+ if ( ! common . hasCrypto )
10
+ common . skip ( 'missing crypto' ) ;
11
+
12
+ const { TLSSocket } = require ( 'tls' ) ;
13
+ const makeDuplexPair = require ( '../common/duplexpair' ) ;
14
+
15
+ let { clientSide } = makeDuplexPair ( ) ;
16
+
17
+ let clientTLS = new TLSSocket ( clientSide , { isServer : false } ) ;
18
+ // eslint-disable-next-line no-unused-vars
19
+ let clientTLSHandle = clientTLS . _handle ;
20
+
21
+ setImmediate ( ( ) => {
22
+ clientTLS = null ;
23
+ global . gc ( ) ;
24
+ clientTLSHandle = null ;
25
+ global . gc ( ) ;
26
+ setImmediate ( ( ) => {
27
+ clientSide = null ;
28
+ global . gc ( ) ;
29
+ } ) ;
30
+ } ) ;
You can’t perform that action at this time.
0 commit comments