Assign the Fiber to self.fiber.

Doing so reveals a deadlock in the stop code (which causes self-test to
fail, yay).  Fix it by trying harder to not stop the (all or app) runner
until after the app runner has processed the "hey you should stop"
return false from onRunEnd.
This commit is contained in:
David Glasser
2014-04-02 19:43:29 -07:00
parent a61dd5c9f3
commit 82aa3485ac
2 changed files with 10 additions and 8 deletions

View File

@@ -242,8 +242,11 @@ exports.run = function (appDir, options) {
result.outcome === "wrong-release" ||
(result.outcome === "terminated" &&
result.signal === undefined && result.code === undefined)) {
runner.stop();
fut.isResolved() || fut['return'](result);
// Allow run() to continue (and call runner.stop()) only once the
// AppRunner has processed our "return false"; otherwise we deadlock.
process.nextTick(function () {
fut.isResolved() || fut['return'](result);
});
return false; // stop restarting
}
runner.regenerateAppPort();

View File

@@ -266,11 +266,9 @@ _.extend(AppProcess.prototype, {
// mongoUrl, oplogUrl, buildOptions, rootUrl, settingsFile, program,
// proxy
//
// To use, construct an instance of AppRunner, and then call start()
// to start it running. Call stop() at any time to shut it down and
// clean it up. You should call stop() to clean up even if you return
// false from onRunEnd(); this stops the restarting but doesn't
// destroy the AppRunner instance.
// To use, construct an instance of AppRunner, and then call start() to start it
// running. To stop it, either return false from onRunEnd, or call stop(). (But
// don't call stop() from inside onRunEnd: that causes a deadlock.)
//
// The 'result' argument to onRunEnd is an object with keys:
//
@@ -338,7 +336,8 @@ _.extend(AppRunner.prototype, {
self.startFuture = new Future;
self.fiber = new Fiber(function () {
self._fiber();
}).run();
});
self.fiber.run();
self.startFuture.wait();
self.startFuture = null;
},