Meteor - broken communication after ddp reconnect

63 views
Skip to first unread message

Adam Wałach

unread,
Oct 6, 2014, 3:35:06 AM10/6/14
to meteo...@googlegroups.com

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 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);
}


To observe this effect do following steps:
1. Run two projects: one with client.js, second with server.js
2. On client you will see messages "calling remote function" and "demo"(returned value) every 2 seconds
3. Restart server, on client you'll see information about reconnection.
4. From this moment there are only messages "
calling remote function", no returned values.
5. "added" events (from subscription) also 
cease to appear.

So the question is: What causes such a behavior?

Reply all
Reply to author
Forward
0 new messages