Skip to content

Commit

Permalink
TLS sockets should not be writable after 'end'
Browse files Browse the repository at this point in the history
Closes GH-694.
  • Loading branch information
ry committed Feb 20, 2011
1 parent c72ae27 commit c2a6295
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
3 changes: 3 additions & 0 deletions lib/tls.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
31 changes: 31 additions & 0 deletions test/disabled/test-https-loop-to-google.js
Original file line number Diff line number Diff line change
@@ -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);
});
}
2 changes: 0 additions & 2 deletions test/simple/test-tls-securepair-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit c2a6295

Please sign in to comment.