Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Release v0.0.20

  • Loading branch information...
commit 306e1b7c882a89f41dc857cc99ed89718d4e5313 1 parent 317b6d2
@pgte authored
View
5 ChangeLog
@@ -1,3 +1,8 @@
+2010.10.05 v0.0.20
+
+* Fixed some important leaks that were preventing node to end after fugue.stop();
+* Added "started" callback to fugue.start();
+
2010.10.03 v0.0.19
* Reviewed the code that synchronously tries to fetch the file descriptor from the original master into the new respawned master (luismreis)
View
2  Makefile
@@ -1,7 +1,7 @@
#all: test
#
test:
- node tools/test.js test_zero_workers test_one_worker test_if_i_can_reach_many_workers test_app_reload test_working_dir test_master_socket_is_protected
+ node tools/test.js test_zero_workers test_one_worker test_if_i_can_reach_many_workers test_app_reload test_working_dir test_master_socket_is_protected test_leaks
test-fail:
node tools/test.js test_should_fail
View
1  README.markdown
@@ -45,6 +45,7 @@ For UNIX sockets:
### Options on fugue.start:
+* started : callback to be invoked when all workers are up and running
* working_path : absolute path for the working dir
* tmp_path : the absolute path for the temp dir. defaults to current_dir/tmp
* log_file : the full path of the log file if you wish stdout to be redirected there. All workers + master will write here. If absent does not touch stdout.
View
38 lib/fugue.js
@@ -1,8 +1,11 @@
+var the_server;
var workers = [];
-var server_socket, fd_server;
-var killer, respawner;
+var workers_started = 0;
+var server_socket;
var master_socket_path;
+var master_server;
+var killer, respawner;
var isMaster = exports.isMaster = function() {
return !process.env._FUGUE_WORKER;
@@ -17,9 +20,6 @@ var masterSocketPath = exports.masterSocketPath = function() {
var stop = exports.stop = function() {
if (isMaster()) {
workers.forEach(function(worker) {
- worker.removeAllListeners(); // Prevent from master respawn
- worker.stdout.removeAllListeners();
- worker.stderr.removeAllListeners();
worker.listeners('exit').forEach(function(listener) {
worker.removeListener('exit', listener);
});
@@ -28,16 +28,26 @@ var stop = exports.stop = function() {
workers = [];
netBinding = process.binding('net');
if (server_socket) netBinding.close(server_socket);
+ if (the_server) {
+ the_server.watcher.stop();
+ the_server = null;
+ }
server_socket = null;
- if (fd_server) fd_server.close();
- fd_server = null;
+ if (master_server) {
+ master_server.close();
+ }
+ master_server = null;
process.removeListener('SIGINT', killer);
process.removeListener('SIGHUP', killer);
process.removeListener('SIGTERM', killer);
process.removeListener('SIGUSR2', respawner);
+ process.removeAllListeners();
}
}
+
exports.start = function(server, port, host, worker_count, options) {
+
+ the_server = server;
function isPort (x) { return parseInt(x) >= 0; }
@@ -103,6 +113,7 @@ exports.start = function(server, port, host, worker_count, options) {
// Redirect stdout and stderr
if (options.log_file) {
+ fs.close(process.stdout.fd);
process.stdout.fd = fs.openSync(options.log_file, 'a');
}
@@ -133,6 +144,7 @@ exports.start = function(server, port, host, worker_count, options) {
log('Starting new master...');
if (options.master_log_file) {
+ fs.close(process.stdout.fd);
process.stdout.fd = fs.openSync(options.master_log_file, 'w');
}
@@ -193,17 +205,21 @@ exports.start = function(server, port, host, worker_count, options) {
log('Have server socket: ' + server_socket);
- fd_server = net.createServer(function(conn) {
+ master_server = net.createServer(function(conn) {
conn.on('data', function(data) {
- log('got data for fd_server');
+ log('got data for master_server');
if (data.toString() == 'GIMME_SOCKET') {
log('serving server socket file descriptor ' + server_socket);
conn.write('HERE_YOU_GO', 'ascii', server_socket);
+ workers_started ++;
+ if (options.started && workers_started == worker_count) options.started();
}
});
- }).listen(master_socket_path);
+ });
+ master_server.listen(master_socket_path);
workers = [];
+ workers_started = 0;
var spawn_worker = function(worker_idx) {
// prepare environment for worker
@@ -232,7 +248,6 @@ exports.start = function(server, port, host, worker_count, options) {
}
- // fork workers
log('Spawning workers...');
process.env._FUGUE_WORKER_COUNT = worker_count;
for (var worker_idx = 0; worker_idx < worker_count; worker_idx ++) {
@@ -248,7 +263,6 @@ exports.start = function(server, port, host, worker_count, options) {
}
// Listen for process exits
- // process.on('exit', world_killer);
process.on('SIGINT', killer);
process.on('SIGHUP', killer);
process.on('SIGTERM', killer);
View
2  package.json
@@ -1,6 +1,6 @@
{ "name" : "fugue"
, "description" : "Unicorn for node for node"
-, "version" : "0.0.19"
+, "version" : "0.0.20"
, "homepage" : "http://www.metaduck.com/fugue"
, "author" : "Pedro Teixeira <pedro.teixeira@gmail.com> (http://www.metaduck.com)"
, "contributors" :
View
2  test/test_app_reload.js
@@ -51,7 +51,7 @@ exports.run = function(next) {
// wait sometime before starting to make calls
setTimeout(function() {
// start making calls
- var intervalId = setInterval(make_call, 1000);
+ var intervalId = setInterval(make_call, 100);
setTimeout(function() {
// Now, restart app
spawned.kill('SIGUSR2');
Please sign in to comment.
Something went wrong with that request. Please try again.