In follower, when calling a method with a callback, do not hang waiting for a connection instead defer the method

This commit is contained in:
Naomi Seyfer
2013-11-04 12:39:42 -08:00
parent 8f27d2cd58
commit 3fc7d35f41
2 changed files with 27 additions and 9 deletions

View File

@@ -92,7 +92,7 @@ Follower = {
electorTries[tryingUrl]++;
}
url = url || findFewestTries();
console.log("trying", url, electorTries, tryingUrl, process.env.GALAXY_JOB);
//console.log("trying", url, electorTries, tryingUrl, process.env.GALAXY_JOB);
// Don't keep trying the same url as fast as we can if it's not working.
if (electorTries[url] > 2) {
@@ -217,8 +217,18 @@ Follower = {
// leadership group.
conn._applyImpl = conn.apply;
conn.apply = function (/* arguments */) {
connectedToLeadershipGroup.wait();
return conn._applyImpl.apply(conn, arguments);
var args = _.toArray(arguments);
if (typeof args[args.length-1] === 'function') {
// this needs to be independent of this fiber if there is a callback.
Meteor.defer(function () {
connectedToLeadershipGroup.wait();
return conn._applyImpl.apply(conn, args);
});
return null; // if there is a callback, the return value is not used
} else {
connectedToLeadershipGroup.wait();
return conn._applyImpl.apply(conn, args);
}
};
conn.onLost = function (callback) {

View File

@@ -450,7 +450,6 @@ var runWebAppServer = function () {
};
} else {
proxyConf = configuration.proxy;
}
Log("Attempting to bind to proxy at " + proxyService.providers.proxy);
console.log(proxyConf);
@@ -477,6 +476,8 @@ var runWebAppServer = function () {
};
};
var proxy;
WebAppInternals.bindToProxy = function (proxyConfig, proxyServiceName) {
var securePort = proxyConfig.securePort || 4433;
var insecurePort = proxyConfig.insecurePort || 8080;
@@ -508,11 +509,18 @@ WebAppInternals.bindToProxy = function (proxyConfig, proxyServiceName) {
// This is run after packages are loaded (in main) so we can use
// Follower.connect.
var proxy = Package["follower-livedata"].Follower.connect(
proxyConfig.proxyEndpoint, {
group: proxyServiceName
}
);
if (proxy) {
proxy.reconnect({
url: proxyConfig.proxyEndpoint
});
} else {
proxy = Package["follower-livedata"].Follower.connect(
proxyConfig.proxyEndpoint, {
group: proxyServiceName
}
);
}
var route = process.env.ROUTE;
var host = route.split(":")[0];
var port = +route.split(":")[1];