Skip to content

Commit 9ac8d41

Browse files
davedoesdevtargos
authored andcommitted
net: check for close on stream, not parent
'close' event isn't emitted on a TLS connection if it's been written to (but 'end' and 'finish' events are). PR-URL: #25026Fixes: #24984 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 91d1aea commit 9ac8d41

2 files changed

Lines changed: 43 additions & 2 deletions

File tree

‎lib/net.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,8 @@ Socket.prototype._final = function(cb) {
368368
};
369369

370370

371-
functionafterShutdown(status,handle){
372-
varself=handle[owner_symbol];
371+
functionafterShutdown(status){
372+
varself=this.handle[owner_symbol];
373373

374374
debug('afterShutdown destroyed=%j',self.destroyed,
375375
self._readableState);
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
'use strict';
2+
constcommon=require('../common');
3+
4+
if(!common.hasCrypto)
5+
common.skip('missing crypto');
6+
7+
// Issue #24984
8+
// 'close' event isn't emitted on a TLS connection if it's been written to
9+
// (but 'end' and 'finish' events are). Without a fix, this test won't exit.
10+
11+
consttls=require('tls');
12+
constfixtures=require('../common/fixtures');
13+
letcconn=null;
14+
letsconn=null;
15+
16+
functiontest(){
17+
if(cconn&&sconn){
18+
cconn.resume();
19+
sconn.resume();
20+
sconn.end(Buffer.alloc(1024*1024));
21+
cconn.end();
22+
}
23+
}
24+
25+
constserver=tls.createServer({
26+
key: fixtures.readKey('agent1-key.pem'),
27+
cert: fixtures.readKey('agent1-cert.pem')
28+
},function(c){
29+
c.on('close',function(){
30+
server.close();
31+
});
32+
sconn=c;
33+
test();
34+
}).listen(0,common.mustCall(function(){
35+
tls.connect(this.address().port,{
36+
rejectUnauthorized: false
37+
},common.mustCall(function(){
38+
cconn=this;
39+
test();
40+
}));
41+
}));

0 commit comments

Comments
 (0)