Skip to content

Commit aa05269

Browse files
committed
tls: nullify .ssl on handle close
This is an intermediate fix for an issue of accessing `TLSWrap` fields after the parent handle was destroyed. While `close` listener cleans up this field automatically, it can be done even earlier at the `TLSWrap.close` call. Proper fix is going to be submitted and landed after this one. Fix: #5108 PR-URL: #5168 Reviewed-By: Shigeki Ohtsu <[email protected]>
1 parent a06066c commit aa05269

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

lib/_tls_wrap.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,9 @@ proxiedMethods.forEach(function(name) {
299299
});
300300

301301
tls_wrap.TLSWrap.prototype.close = function closeProxy(cb) {
302+
if (this.owner)
303+
this.owner.ssl = null;
304+
302305
if (this._parentWrap && this._parentWrap._handle === this._parent) {
303306
this._parentWrap.once('close', cb);
304307
return this._parentWrap.destroy();
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
'use strict';
2+
const common = require('../common');
3+
4+
if (!common.hasCrypto) {
5+
console.log('1..0 # Skipped: missing crypto');
6+
return;
7+
}
8+
9+
const assert = require('assert');
10+
const tls = require('tls');
11+
const fs = require('fs');
12+
13+
const options = {
14+
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
15+
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem')
16+
};
17+
18+
19+
const server = tls.createServer(options, function(s) {
20+
s.end('hello');
21+
}).listen(common.PORT, function() {
22+
const opts = {
23+
port: common.PORT,
24+
rejectUnauthorized: false
25+
};
26+
const client = tls.connect(opts, function() {
27+
putImmediate(client);
28+
});
29+
});
30+
31+
32+
function putImmediate(client) {
33+
setImmediate(function() {
34+
if (client.ssl) {
35+
const fd = client.ssl.fd;
36+
assert(!!fd);
37+
putImmediate(client);
38+
} else {
39+
server.close();
40+
}
41+
});
42+
}

0 commit comments

Comments
 (0)