Browse files

Fix possible socket leaks.

Fixes #2.
Fixes #3.
  • Loading branch information...
1 parent 67005bc commit da4c50991d202267513b37b8f6e7212ea7b75b55 @koichik committed May 26, 2012
Showing with 10 additions and 9 deletions.
  1. +2 −1 lib/tunnel.js
  2. +2 −2 test/http-over-http.js
  3. +2 −2 test/http-over-https.js
  4. +2 −2 test/https-over-http.js
  5. +2 −2 test/https-over-https.js
View
3 lib/tunnel.js
@@ -88,7 +88,7 @@ TunnelingAgent.prototype.addRequest = function addRequest(req, host, port) {
}
function onCloseOrRemove(err) {
- self.removeSocket();
+ self.removeSocket(socket);
socket.removeListener('free', onFree);
socket.removeListener('close', onCloseOrRemove);
socket.removeListener('agentRemove', onCloseOrRemove);
@@ -190,6 +190,7 @@ function createSecureSocket(options, cb) {
var secureSocket = tls.connect(0, mergeOptions({}, self.options, {
socket: socket
}));
+ self.sockets[self.sockets.indexOf(socket)] = secureSocket;
cb(secureSocket);
});
}
View
4 test/http-over-http.js
@@ -99,8 +99,8 @@ describe('HTTP over HTTP', function() {
proxyConnect.should.equal(poolSize);
clientConnect.should.equal(N);
- agent.sockets.should.have.lengthOf(0);
- agent.requests.should.have.lengthOf(0);
+ agent.sockets.should.be.empty;
+ agent.requests.should.be.empty;
done();
});
View
4 test/http-over-https.js
@@ -113,8 +113,8 @@ describe('HTTP over HTTPS', function() {
clientConnect.should.equal(N);
var name = 'localhost:' + serverPort;
- agent.sockets.should.not.have.ownProperty(name);
- agent.requests.should.not.have.ownProperty(name);
+ agent.sockets.should.be.empty;
+ agent.requests.should.be.empty;
done();
});
View
4 test/https-over-http.js
@@ -112,8 +112,8 @@ describe('HTTPS over HTTP', function() {
clientConnect.should.equal(N);
var name = 'localhost:' + serverPort;
- agent.sockets.should.not.have.ownProperty(name);
- agent.requests.should.not.have.ownProperty(name);
+ agent.sockets.should.be.empty;
+ agent.requests.should.be.empty;
done();
});
View
4 test/https-over-https.js
@@ -120,8 +120,8 @@ describe('HTTPS over HTTPS', function() {
clientConnect.should.equal(N);
var name = 'localhost:' + serverPort;
- agent.sockets.should.not.have.ownProperty(name);
- agent.requests.should.not.have.ownProperty(name);
+ agent.sockets.should.be.empty;
+ agent.requests.should.be.empty;
done();
});

0 comments on commit da4c509

Please sign in to comment.