From d2319bc134f94c99435bc84a4c3ada658b4bd2e4 Mon Sep 17 00:00:00 2001 From: Avital Oliver Date: Fri, 25 Jan 2013 18:47:27 -0800 Subject: [PATCH] Wrap some CLI functions in a Fiber --- app/lib/fiber-helpers.js | 21 +++++++++++++++++++++ app/meteor/deploy.js | 3 +++ app/meteor/run.js | 5 +++-- 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 app/lib/fiber-helpers.js diff --git a/app/lib/fiber-helpers.js b/app/lib/fiber-helpers.js new file mode 100644 index 0000000000..ff847f3c0f --- /dev/null +++ b/app/lib/fiber-helpers.js @@ -0,0 +1,21 @@ +// node (v8) defaults to only recording 10 lines of stack trace. +// this becomes especially bad when using fibers, since you get deeper +// stack traces that would have been split up between different callbacks +// +// this only affects the `meteor` executable, not server code on +// meteor apps. +Error.stackTraceLimit = Infinity; // http://code.google.com/p/v8/wiki/JavaScriptStackTraceApi + +var Fiber = require("fibers"); + +// runs a function within a fiber. we wrap the entry point into meteor.js into a fiber +// but if you use callbacks that call synchronous code you need to wrap those as well. +// +// NOTE: It's probably better to not use callbacks. Instead you can +// use Futures to generate synchronous equivalents. +exports.inFiber = function(func) { + return function() { + new Fiber(func).run(); + }; +}; + diff --git a/app/meteor/deploy.js b/app/meteor/deploy.js index a64370dc02..d06953c13c 100644 --- a/app/meteor/deploy.js +++ b/app/meteor/deploy.js @@ -13,6 +13,7 @@ var files = require(path.join(__dirname, '..', 'lib', 'files.js')); var _ = require('underscore'); var keypress = require('keypress'); var child_process = require('child_process'); +var inFiber = require(path.join(__dirname, '..', 'lib', 'fiber-helpers.js')).inFiber; // // configuration @@ -352,6 +353,8 @@ var read_password = function (callback) { var with_password = function (site, callback) { var check_url = "https://" + DEPLOY_HOSTNAME + "/has_password/" + site; + callback = inFiber(callback); + request(check_url, function (error, response, body) { if (error || response.statusCode !== 200) { callback(); diff --git a/app/meteor/run.js b/app/meteor/run.js index 2a02fd3007..7def3aac64 100644 --- a/app/meteor/run.js +++ b/app/meteor/run.js @@ -11,6 +11,7 @@ var updater = require(path.join(__dirname, '..', 'lib', 'updater.js')); var bundler = require(path.join(__dirname, '..', 'lib', 'bundler.js')); var mongo_runner = require(path.join(__dirname, '..', 'lib', 'mongo_runner.js')); var mongoExitCodes = require(path.join(__dirname, '..', 'lib', 'mongo_exit_codes.js')); +var inFiber = require(path.join(__dirname, '..', 'lib', 'fiber-helpers.js')).inFiber; var _ = require('underscore'); @@ -601,7 +602,7 @@ exports.run = function (app_dir, bundle_opts, port, once, settingsFile) { } }; - var restart_server = function () { + var restart_server = inFiber(function () { Status.running = false; Status.listening = false; if (server_handle) @@ -700,7 +701,7 @@ exports.run = function (app_dir, bundle_opts, port, once, settingsFile) { }}); } }; - }; + }); var mongo_err_count = 0;