Skip to content

Commit c2a6295

Browse files
committed
TLS sockets should not be writable after 'end'
Closes GH-694.
1 parent c72ae27 commit c2a6295

4 files changed

Lines changed: 36 additions & 3 deletions

File tree

lib/http.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1282,7 +1282,8 @@ Agent.prototype._establishNewConnection = function() {
12821282
// but outgoingFlush instead.
12831283
if (!req.shouldKeepAlive) {
12841284
debug('AGENT socket.end()');
1285-
socket.end();
1285+
if (socket.writable) socket.end();
1286+
assert(!socket.writable);
12861287
} else {
12871288
debug('AGENT socket keep-alive');
12881289
}

lib/tls.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,9 @@ SecurePair.prototype._destroy = function() {
553553
this._ssl.close();
554554
this._ssl = null;
555555

556+
self.encrypted.writable = self.encrypted.readable = false;
557+
self.cleartext.writable = self.cleartext.readable = false;
558+
556559
process.nextTick(function() {
557560
self.encrypted.emit('end');
558561
if (self.encrypted.onend) self.encrypted.onend();
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Failing test for https
2+
3+
// Will fail with "socket hang up" for 4 out of 10 requests
4+
// Tested on node 0.5.0-pre commit 9851574
5+
6+
7+
var https = require('https');
8+
9+
for(var i = 0; i < 10; ++i)
10+
{
11+
https.get(
12+
{
13+
host: 'www.google.com',
14+
path: '/accounts/o8/id',
15+
port: 443,
16+
}, function(res)
17+
{
18+
var data = '';
19+
res.on('data', function(chunk)
20+
{
21+
data += chunk;
22+
});
23+
res.on('end', function()
24+
{
25+
console.log(res.statusCode);
26+
});
27+
}).on('error', function(error)
28+
{
29+
console.log(error);
30+
});
31+
}

test/simple/test-tls-securepair-server.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ var server = net.createServer(function(socket) {
5252

5353
socket.on('end', function() {
5454
log('socket end');
55-
pair.cleartext.write('goodbye\r\n');
56-
pair.cleartext.end();
5755
});
5856

5957
pair.cleartext.on('error', function(err) {

0 commit comments

Comments
 (0)