Skip to content

Commit f17b61e

Browse files
davedoesdevMylesBorins
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 <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent 5f72f39 commit f17b61e

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

‎lib/net.js‎

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

364364

365-
functionafterShutdown(status,handle){
366-
varself=handle[owner_symbol];
365+
functionafterShutdown(status){
366+
varself=this.handle[owner_symbol];
367367

368368
debug('afterShutdown destroyed=%j',self.destroyed,
369369
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)