Permalink
Browse files

Fix memory leak

  • Loading branch information...
1 parent 0365b8d commit 8392d043f10c671173d03d8caf545af30cbe4e20 @jcheng5 jcheng5 committed Mar 29, 2013
Showing with 37 additions and 1 deletion.
  1. +6 −1 lib/worker/worker-registry.js
  2. +31 −0 test/test-worker-registry-leak.js
@@ -61,7 +61,6 @@ function connect_p(host, port, interval, timeout, shouldStop) {
return defer.promise;
}
-
var WorkerRegistry = function() {
this.$workers = map.create();
};
@@ -97,6 +96,12 @@ module.exports = WorkerRegistry;
err.consoleLogFile = logFilePath;
defer.reject(err);
};
+ // Once defer is fulfilled, doReject is essentially a no-op. The following
+ // (making doReject *actually* a no-op) may seem redundant, but it is
+ // necessary to prevent a memory leak!
+ defer.promise.fin(function() {
+ doReject = function() {};
+ });
this.allocPort_p()
.then(function(listenPort) {
@@ -0,0 +1,31 @@
+var util = require('util');
+require('../lib/core/log')
+var fs = require('fs');
+var AppSpec = require('../lib/worker/app-spec');
+var WorkerRegistry = require('../lib/worker/worker-registry');
+
+SHINY_SERVER_VERSION = "0.3.4";
+
+var registry = new WorkerRegistry();
+setInterval(function() {
+ registry.getWorker_p(new AppSpec(
+ '/var/shiny-server/www/09_upload', 'shiny', '', '/var/shiny-server/log', {
+ random: process.uptime()
+ }))
+ .then(function(info) {
+ info.acquire();
+ info.release();
+ })
+ .done();
+
+ return true;
+}, 100);
+
+agent = require('webkit-devtools-agent')
+
+setInterval(function() {
+ var mu = process.memoryUsage();
+ var info = process.uptime() + ',' + mu.rss + ',' + mu.heapTotal + ',' + mu.heapUsed + '\n';
+ fs.appendFile('mem-' + process.pid + '.csv', info);
+ return true;
+}, 3000);

0 comments on commit 8392d04

Please sign in to comment.