I'm writing application consisting of two modules - client and server. Server publishes recordset and function, client subscribes on recordset and calls remote functions. Both modules run server side. Everything works as expected until the reconnection of ddp session (i.e server restart). After the reconnect, remote function calls cease to return any values, subscription is also broken (no events).
I was able to find two operations which used simultaneously cause this effect. Its "self.ready()" and calling any remote function inside reconnect handler. If I remove any of that then everything go backs to normal.
Server:
if (Meteor.isServer) {
Meteor.publish("pname", function () {
var self = this;
var id = Random.id();
self.added("pname", id, {"init": "demo"});
self.ready();
Meteor.setInterval(function(){
var id = Random.id();
self.added("pname", id, {"init": "test"});
self.removed("pname", id);
}, 2000);
});
Meteor.methods({
'demo': function (){
console.log('demo function called');
return 'demo';
}
});
}
Client:
if (Meteor.isServer) {
var remote = DDP.connect("http://example.com:3000");
remote.onReconnect = function() {
console.log('reconnect');
console.log('calling remote function inside reconnect');
var temp = remote.call('demo');
console.log(temp);
};
var collection = new Meteor.Collection("pname", remote);
collection.find({}).observe({
"added": function(item) {
console.log('added', item);
}
});
remote.subscribe("pname");
Meteor.setInterval(function(){
console.log('calling remote function');
var temp = remote.call('demo');
console.log('Result: ' + temp); //after reconnect this line is not called
}, 2000);
}
So the question is: What causes such a behavior?