File tree Expand file tree Collapse file tree 4 files changed +60
-1
lines changed
Expand file tree Collapse file tree 4 files changed +60
-1
lines changed Original file line number Diff line number Diff line change @@ -391,6 +391,12 @@ TLSSocket.prototype._wrapHandle = function(wrap){
391391res = null ;
392392} ) ;
393393
394+ if ( wrap ) {
395+ wrap . on ( 'close' , function ( ) {
396+ res . onStreamClose ( ) ;
397+ } ) ;
398+ }
399+
394400return res ;
395401} ;
396402
Original file line number Diff line number Diff line change @@ -523,7 +523,7 @@ int TLSWrap::GetFD(){
523523
524524
525525bool TLSWrap::IsAlive (){
526- return ssl_ != nullptr && stream_->IsAlive ();
526+ return ssl_ != nullptr && stream_ != nullptr && stream_ ->IsAlive ();
527527}
528528
529529
@@ -783,6 +783,14 @@ void TLSWrap::EnableSessionCallbacks(
783783}
784784
785785
786+ void TLSWrap::OnStreamClose (const FunctionCallbackInfo<Value>& args){
787+ TLSWrap* wrap;
788+ ASSIGN_OR_RETURN_UNWRAP (&wrap, args.Holder ());
789+
790+ wrap->stream_ = nullptr ;
791+ }
792+
793+
786794void TLSWrap::DestroySSL (const FunctionCallbackInfo<Value>& args){
787795 TLSWrap* wrap;
788796ASSIGN_OR_RETURN_UNWRAP (&wrap, args.Holder ());
@@ -913,6 +921,7 @@ void TLSWrap::Initialize(Local<Object> target,
913921 env->SetProtoMethod (t, " enableSessionCallbacks" , EnableSessionCallbacks);
914922 env->SetProtoMethod (t, " destroySSL" , DestroySSL);
915923 env->SetProtoMethod (t, " enableCertCb" , EnableCertCb);
924+ env->SetProtoMethod (t, " onStreamClose" , OnStreamClose);
916925
917926 StreamBase::AddMethods<TLSWrap>(env, t, StreamBase::kFlagHasWritev );
918927 SSLWrap<TLSWrap>::AddMethods (env, t);
Original file line number Diff line number Diff line change @@ -135,6 +135,7 @@ class TLSWrap : public AsyncWrap,
135135static void EnableCertCb (
136136const v8::FunctionCallbackInfo<v8::Value>& args);
137137static void DestroySSL (const v8::FunctionCallbackInfo<v8::Value>& args);
138+ static void OnStreamClose (const v8::FunctionCallbackInfo<v8::Value>& args);
138139
139140#ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
140141static void GetServername (const v8::FunctionCallbackInfo<v8::Value>& args);
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+ const common = require ( '../common' ) ;
3+ const assert = require ( 'assert' ) ;
4+
5+ const tls = require ( 'tls' ) ;
6+ const fs = require ( 'fs' ) ;
7+ const net = require ( 'net' ) ;
8+
9+ const key = fs . readFileSync ( common . fixturesDir + '/keys/agent2-key.pem' ) ;
10+ const cert = fs . readFileSync ( common . fixturesDir + '/keys/agent2-cert.pem' ) ;
11+
12+ const T = 100 ;
13+
14+ // tls server
15+ const tlsServer = tls . createServer ( { cert, key } , ( socket ) => {
16+ setTimeout ( ( ) => {
17+ socket . on ( 'error' , ( error ) => {
18+ assert . strictEqual ( error . code , 'EINVAL' ) ;
19+ tlsServer . close ( ) ;
20+ netServer . close ( ) ;
21+ } ) ;
22+ socket . write ( 'bar' ) ;
23+ } , T * 2 ) ;
24+ } ) ;
25+
26+ // plain tcp server
27+ const netServer = net . createServer ( ( socket ) => {
28+ // if client wants to use tls
29+ tlsServer . emit ( 'connection' , socket ) ;
30+
31+ socket . setTimeout ( T , ( ) => {
32+ // this breaks if TLSSocket is already managing the socket:
33+ socket . destroy ( ) ;
34+ } ) ;
35+ } ) . listen ( 0 , common . mustCall ( function ( ) {
36+
37+ // connect client
38+ tls . connect ( {
39+ host : 'localhost' ,
40+ port : this . address ( ) . port ,
41+ rejectUnauthorized : false
42+ } ) . write ( 'foo' ) ;
43+ } ) ) ;
You can’t perform that action at this time.
0 commit comments