Skip to content

Commit aed04b8

Browse files
indutnyrvagg
authored andcommitted
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 98907c7 commit aed04b8

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

lib/_tls_wrap.js

+3
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,9 @@ proxiedMethods.forEach(function(name) {
314314
});
315315

316316
tls_wrap.TLSWrap.prototype.close = function closeProxy(cb) {
317+
if (this.owner)
318+
this.owner.ssl = null;
319+
317320
if (this._parentWrap && this._parentWrap._handle === this._parent) {
318321
this._parentWrap.once('close', cb);
319322
return this._parentWrap.destroy();
+42
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)