forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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: nodejs#5108
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
|
||
if (!common.hasCrypto) { | ||
console.log('1..0 # Skipped: node compiled without crypto.'); | ||
return; | ||
} | ||
|
||
const assert = require('assert'); | ||
const tls = require('tls'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const keyDir = path.join(common.fixturesDir, 'keys'); | ||
const key = fs.readFileSync(path.join(keyDir, 'agent1-key.pem')); | ||
const cert = fs.readFileSync(path.join(keyDir, 'agent1-cert.pem')); | ||
|
||
const server = tls.createServer({ | ||
key: key, | ||
cert: cert | ||
}, function(c) { | ||
c.end(); | ||
}).listen(common.PORT, function() { | ||
var client = tls.connect({ | ||
port: common.PORT, | ||
rejectUnauthorized: false | ||
}, common.mustCall(function() { | ||
client.destroy(); | ||
if (!client._events.close) | ||
client._events.close = []; | ||
else if (!Array.isArray(client._events.close)) | ||
client._events.close = [ client._events.close ]; | ||
|
||
client._events.close.unshift(common.mustCall(function() { | ||
setImmediate(function() { | ||
// Make it crash on unpatched node.js | ||
var fd = client.ssl && client.ssl.fd; | ||
assert(client.ssl === null); | ||
assert(!fd); | ||
}); | ||
})); | ||
server.close(); | ||
})); | ||
}); |