Attempt more reliable handling for connecting with a bad instance ID.
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import json
|
||||
import logging
|
||||
import webapp2
|
||||
|
||||
@@ -29,7 +30,11 @@ class OnChannelConnect(webapp2.RequestHandler):
|
||||
instance_id = self.request.get('from')
|
||||
instance = models.Instance.FromID(instance_id)
|
||||
if not instance:
|
||||
logging.error('Channel opened with invalid instance_id: %s', instance_id)
|
||||
logging.warning('Channel opened with invalid instance_id: %s', instance_id)
|
||||
message = {
|
||||
'event_type': 'close',
|
||||
}
|
||||
channel.send_message(instance_id, json.dumps(msg, default=utils.EncodeJSON))
|
||||
return
|
||||
instance.active = True
|
||||
instance.put()
|
||||
|
||||
@@ -422,7 +422,11 @@ Cosmopolite.prototype.unpin = function(id) {
|
||||
* @private
|
||||
*/
|
||||
Cosmopolite.prototype.loggingPrefix_ = function() {
|
||||
return 'cosmopolite (' + this.namespace_ + '):';
|
||||
if (this.instanceID_) {
|
||||
return 'cosmopolite (' + this.namespace_ + ' / ' + this.instanceID_ + '):';
|
||||
} else {
|
||||
return 'cosmopolite (' + this.namespace_ + '):';
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -605,7 +609,7 @@ Cosmopolite.prototype.sendRPCs_ = function(commands, delay) {
|
||||
return;
|
||||
}
|
||||
var request = {
|
||||
'instance_id': this.instanceId_,
|
||||
'instance_id': this.instanceID_,
|
||||
'commands': [],
|
||||
};
|
||||
commands.forEach(function(command) {
|
||||
@@ -786,7 +790,7 @@ Cosmopolite.prototype.createChannel_ = function() {
|
||||
}
|
||||
|
||||
/** @type {string} */
|
||||
this.instanceId_ = this.uuid_();
|
||||
this.instanceID_ = this.uuid_();
|
||||
|
||||
var rpcs = [
|
||||
{
|
||||
@@ -899,6 +903,18 @@ Cosmopolite.prototype.onSocketError_ = function(msg) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Callback on receiving a 'close' event from the server
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
Cosmopolite.prototype.onClose_ = function() {
|
||||
console.log(this.loggingPrefix_(), 'server asked us to close our socket');
|
||||
if (this.socket_) {
|
||||
this.socket_.close();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Callback on receiving a 'login' event from the server
|
||||
*
|
||||
@@ -1060,6 +1076,9 @@ Cosmopolite.prototype.onServerEvent_ = function(e) {
|
||||
this.profilePromises_ = [];
|
||||
}
|
||||
switch (e['event_type']) {
|
||||
case 'close':
|
||||
this.onClose_();
|
||||
break;
|
||||
case 'login':
|
||||
this.onLogin_(/** @type {typeLogin} */ (e));
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user