DDP between two servers doesn't reconnect

前端 未结 3 565
感动是毒
感动是毒 2021-01-14 23:57

I have two meteor applications connected via DDP on different servers and server A send data to server B. This is the way they work.

Server A



        
相关标签:
3条回答
  • 2021-01-14 23:59

    I revised a sample of communication between two ddp server, based on camilosw's code.

    Server A as Cloud Data Center. Server B as Data Source, if some data changed, should be send to Server A.

    You can find the code from https://github.com/iascchen/ddp-servers-test

    0 讨论(0)
  • 2021-01-15 00:05

    Emily Stark, from the Meteor Team, confirmed that this is due to a missing feature on the current implementation (version 0.7.0.1 at the moment I write this answer). Their answer is here https://github.com/meteor/meteor/issues/1543. Below is their answer and a workaround she suggest:

    The server-to-server connection is not reconnecting because Meteor currently doesn't do any heartbeating on server-to-server DDP connections. Just as in any other TCP connection, once you switch to a different router, no data can be sent or received on the connection, but the client will not notice unless it attempts to send some data and times out. This differs from browser-to-server DDP connections, which run over SockJS. SockJS does its own heartbeating that we can use to detect dead connections.

    To see this in action, here is some code that I added to server-b in your example:

    var heartbeatOutstanding = false;
    Meteor.setInterval(function () {
      if (! heartbeatOutstanding) {
       console.log("Sending heartbeat");
        remote.call("heartbeat", function () {
          console.log("Heartbeat returned");
          heartbeatOutstanding = false;
        });
        heartbeatOutstanding = true;
      }
    }, 3000);
    
    remote.onReconnect = function () {
      console.log("RECONNECTING REMOTE");
    };
    

    With this code added in there, server-b will reconnect after a long enough time goes by without an ACK from server-a for the TCP segments that are delivering the heartbeat method call. On my machine, this is just a couple minutes, and I get an ETIMEDOUT followed by a reconnect.

    I've opened a separate task for us to think about implementing heartbeating on server-to-server DDP connections during our next bug week. In the meantime, you can always implement heartbeating in your application to ensure that a DDP reconnection happens if the client can no longer talk to the server.

    0 讨论(0)
  • 2021-01-15 00:07

    I think you are not passing DDP connection object to the Collection correctly, try:

    var remote = DDP.connect('http://server-a/');
    Items = new Meteor.Collection('items', { connection: remote }); 
    

    It might be useful for debugging to try all these connection games from the browser console first, since Meteor provides the same API of connection/collections on the client (except for the control flow). Just open any Meteor application and try this lines from the console.

    0 讨论(0)
提交回复
热议问题