Permalink
Browse files

Clean up ServiceConnection timer when we receive a result.

Previously, we could make a connection, do some method calls, and then
10 seconds later the connection happens to be dropped and the connection
timer fires, which not only throws an unexpected error into the future,
but also resolves the future twice. I think ServiceConnection is just
supposed to time out if you don't hear anything from the server within
10 seconds, so it now no longer times out if you hear things from the
server but then happen to be not connected when 10 seconds has elapsed.
  • Loading branch information...
1 parent bc4524b commit 9c1dc8782cbd2c535261216073f0bf9a178dd42f Emily Stark committed Feb 27, 2014
Showing with 13 additions and 5 deletions.
  1. +13 −5 tools/deploy-galaxy.js
View
@@ -117,10 +117,12 @@ _.extend(ServiceConnection.prototype, {
var args = _.toArray(arguments);
var name = args.shift();
self.connection.apply(name, args, function (err, result) {
- if (err)
+ if (err) {
fut['throw'](err);
- else
+ } else {
+ self._cleanUpTimer();
fut['return'](result);
+ }
});
return fut.wait();
@@ -141,6 +143,7 @@ _.extend(ServiceConnection.prototype, {
args.push({
onReady: function () {
ready = true;
+ self._cleanUpTimer();
fut['return']();
},
onError: function (e) {
@@ -156,6 +159,13 @@ _.extend(ServiceConnection.prototype, {
return sub;
},
+ _cleanUpTimer: function () {
+ var self = this;
+ var Package = getPackage();
+ Package.meteor.Meteor.clearTimeout(self.connectionTimer);
+ self.connectionTimer = null;
+ },
+
close: function () {
var self = this;
if (self.connection) {
@@ -164,9 +174,7 @@ _.extend(ServiceConnection.prototype, {
}
if (self.connectionTimer) {
// Clean up the timer so that Node can exit cleanly
- var Package = getPackage();
- Package.meteor.Meteor.clearTimeout(self.connectionTimer);
- self.connectionTimer = null;
+ self._cleanUpTimer();
}
}
});

0 comments on commit 9c1dc87

Please sign in to comment.