From c2a62951f64d5584d76fea5865e9bd94a898ed8b Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Sat, 19 Feb 2011 17:51:32 -0800 Subject: [PATCH] TLS sockets should not be writable after 'end' Closes GH-694. --- lib/http.js | 3 ++- lib/tls.js | 3 +++ test/disabled/test-https-loop-to-google.js | 31 ++++++++++++++++++++++ test/simple/test-tls-securepair-server.js | 2 -- 4 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 test/disabled/test-https-loop-to-google.js diff --git a/lib/http.js b/lib/http.js index c208990c903..af6a40932b0 100644 --- a/lib/http.js +++ b/lib/http.js @@ -1282,7 +1282,8 @@ Agent.prototype._establishNewConnection = function() { // but outgoingFlush instead. if (!req.shouldKeepAlive) { debug('AGENT socket.end()'); - socket.end(); + if (socket.writable) socket.end(); + assert(!socket.writable); } else { debug('AGENT socket keep-alive'); } diff --git a/lib/tls.js b/lib/tls.js index 9760490b614..e27d1aa0cea 100644 --- a/lib/tls.js +++ b/lib/tls.js @@ -553,6 +553,9 @@ SecurePair.prototype._destroy = function() { this._ssl.close(); this._ssl = null; + self.encrypted.writable = self.encrypted.readable = false; + self.cleartext.writable = self.cleartext.readable = false; + process.nextTick(function() { self.encrypted.emit('end'); if (self.encrypted.onend) self.encrypted.onend(); diff --git a/test/disabled/test-https-loop-to-google.js b/test/disabled/test-https-loop-to-google.js new file mode 100644 index 00000000000..dd3bae8c62c --- /dev/null +++ b/test/disabled/test-https-loop-to-google.js @@ -0,0 +1,31 @@ +// Failing test for https + +// Will fail with "socket hang up" for 4 out of 10 requests +// Tested on node 0.5.0-pre commit 9851574 + + +var https = require('https'); + +for(var i = 0; i < 10; ++i) +{ + https.get( + { + host: 'www.google.com', + path: '/accounts/o8/id', + port: 443, + }, function(res) + { + var data = ''; + res.on('data', function(chunk) + { + data += chunk; + }); + res.on('end', function() + { + console.log(res.statusCode); + }); + }).on('error', function(error) + { + console.log(error); + }); +} diff --git a/test/simple/test-tls-securepair-server.js b/test/simple/test-tls-securepair-server.js index ece3c5d01fb..86998b65fe1 100644 --- a/test/simple/test-tls-securepair-server.js +++ b/test/simple/test-tls-securepair-server.js @@ -52,8 +52,6 @@ var server = net.createServer(function(socket) { socket.on('end', function() { log('socket end'); - pair.cleartext.write('goodbye\r\n'); - pair.cleartext.end(); }); pair.cleartext.on('error', function(err) {