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: #25026 Fixes: #24984 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent 91d1aea commit 9ac8d41

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

lib/net.js

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

370370

371-
function afterShutdown(status, handle) {
372-
var self = handle[owner_symbol];
371+
function afterShutdown(status) {
372+
var self = this.handle[owner_symbol];
373373

374374
debug('afterShutdown destroyed=%j', self.destroyed,
375375
self._readableState);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
'use strict';
2+
const common = 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+
const tls = require('tls');
12+
const fixtures = require('../common/fixtures');
13+
let cconn = null;
14+
let sconn = null;
15+
16+
function test() {
17+
if (cconn && sconn) {
18+
cconn.resume();
19+
sconn.resume();
20+
sconn.end(Buffer.alloc(1024 * 1024));
21+
cconn.end();
22+
}
23+
}
24+
25+
const server = 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)