Skip to content

Commit

Permalink
Remove function reference if callback has fired
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvbird committed Apr 23, 2012
1 parent c201e69 commit e57da27
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
15 changes: 14 additions & 1 deletion src/http-server.js
Expand Up @@ -84,6 +84,7 @@ function HTTPServer(port, host, stat_func, bosh_request_handler, http_error_hand

var req_parts = [ ];
var req_body_length = 0;
var req_list_idx = -1;

var _on_end_callback = us.once(function (err) {
if (err) {
Expand All @@ -104,11 +105,21 @@ function HTTPServer(port, host, stat_func, bosh_request_handler, http_error_hand
}
}
req_parts = null;

// Clear the callback to help free memory.
if (req_list_idx > -1) {
if (req_list1[req_list_idx] == _on_end_callback) {
req_list1[req_list_idx] = null;
} else if (req_list2[req_list_idx] == _on_end_callback) {
req_list2[req_list_idx] = null;
}
}
});

// Timeout the request if we don't get an 'end' event within
// 15 sec of the request being made.
req_list1.push(_on_end_callback);
req_list_idx = req_list1.length - 1;

req.on('data', function (d) {
req_body_length += d.length;
Expand Down Expand Up @@ -190,7 +201,9 @@ function HTTPServer(port, host, stat_func, bosh_request_handler, http_error_hand
function handle_request_timeout() {
var i;
for (i = 0; i < req_list2.length; ++i) {
req_list2[i](new Error("Timed Out"));
if (req_list2[i]) {
req_list2[i](new Error("Timed Out"));
}
}
req_list2 = req_list1;
req_list1 = [ ];
Expand Down
5 changes: 3 additions & 2 deletions tests/stress.js
Expand Up @@ -100,7 +100,8 @@ function do_test(domain, route) {
port: u.port,
path: u.pathname,
method: 'POST',
body: sess_create.toString()
body: sess_create.toString(),
agent: false
};

console.log('Connecting to:', domain);
Expand Down Expand Up @@ -156,7 +157,7 @@ function do_test(domain, route) {
function start_test(options) {
var u = url.parse(options.endpoint);
//var agent = http.getAgent(u.hostname, u.port);
http.globalAgent.maxSockets = options.nconn;
// http.globalAgent.maxSockets = options.nconn;

var i;
for (i = 0; i < options.nsess; ++i) {
Expand Down

0 comments on commit e57da27

Please sign in to comment.