Commit f753a9fe authored by Anael Beutot's avatar Anael Beutot
Browse files

Reconnects RPC after a 1 seconds delay.

parent 3fc6b7e9
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -206,6 +206,7 @@ class MainLoop(object):
        self.rpc_con = None

        self.connect = RPCStartHandler(self)
        self.reconnect = None

        # role
        self.role = None
@@ -296,11 +297,19 @@ class MainLoop(object):
        logger.error('Lost connection to the cc-server, will attempt'
                     ' reconnection')

        # reconnection atempt in one second
        self.reconnect = self.evloop.timer(
            1.,0., self.restart_rpc_connection_cb)
        self.reconnect.start()

    def restart_rpc_connection_cb(self, *args):
        # clear connection
        self.rpc_con = None
        # attempt to connect to the cc-server again
        self.connect = RPCStartHandler(self)
        self.connect.start()
        self.reconnect.stop()
        self.reconnect = None

    def start(self):
        logger.info('Starting node')
@@ -315,6 +324,8 @@ class MainLoop(object):
        logger.info('Exiting node...')
        if self.connect is not None:
            self.connect.stop()
        if self.reconnect is not None:
            self.reconnect.stop()
        # close rpc
        if self.rpc_con is not None:
            # disable callback to prevent trampoline calls