From 26f354b3a9113a41c6d9a7d5d71dac0ffba11809 Mon Sep 17 00:00:00 2001 From: Hemna Date: Mon, 24 Jul 2023 17:02:17 -0400 Subject: [PATCH] Max out the client reconnect backoff to 5 This patch adjusts the backoff mechanism for aprs client reconnect to a max backoff sleep of 5 seconds. This prevents an exponential backoff when connection retrying. --- ChangeLog | 1 + aprsd/client.py | 8 +++++++- aprsd/cmds/webchat.py | 8 ++++++-- aprsd/rpc/server.py | 5 ++++- aprsd/threads/rx.py | 1 + 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4233465..ccb0118 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,7 @@ CHANGES v3.1.0 ------ +* Changelog updates for v3.1.0 * Use CONF.admin.web\_port for single launch web admin * Fixed sio namespace registration * Update Dockerfile-dev to include uwsgi diff --git a/aprsd/client.py b/aprsd/client.py index f110236..5121a5b 100644 --- a/aprsd/client.py +++ b/aprsd/client.py @@ -49,8 +49,10 @@ class Client: @property def client(self): if not self._client: + LOG.info("Creating APRS client") self._client = self.setup_connection() if self.filter: + LOG.info("Creating APRS client filter") self._client.set_filter(self.filter) return self._client @@ -159,7 +161,11 @@ class APRSISClient(Client): LOG.error(f"Unable to connect to APRS-IS server. '{e}' ") connected = False time.sleep(backoff) - backoff = backoff * 2 + # Don't allow the backoff to go to inifinity. + if backoff > 5: + backoff = 5 + else: + backoff += 1 continue LOG.debug(f"Logging in to APRS-IS with user '{user}'") self._client = aprs_client diff --git a/aprsd/cmds/webchat.py b/aprsd/cmds/webchat.py index fbdc87d..e387621 100644 --- a/aprsd/cmds/webchat.py +++ b/aprsd/cmds/webchat.py @@ -265,8 +265,12 @@ def _stats(): time_format = "%m-%d-%Y %H:%M:%S" stats_dict = stats_obj.stats() # Webchat doesnt need these - del stats_dict["aprsd"]["watch_list"] - del stats_dict["aprsd"]["seen_list"] + if "watch_list" in stats_dict["aprsd"]: + del stats_dict["aprsd"]["watch_list"] + if "seen_list" in stats_dict["aprsd"]: + del stats_dict["aprsd"]["seen_list"] + if "threads" in stats_dict["aprsd"]: + del stats_dict["aprsd"]["threads"] # del stats_dict["email"] # del stats_dict["plugins"] # del stats_dict["messages"] diff --git a/aprsd/rpc/server.py b/aprsd/rpc/server.py index 924112d..2e053f9 100644 --- a/aprsd/rpc/server.py +++ b/aprsd/rpc/server.py @@ -18,7 +18,10 @@ LOG = logging.getLogger("APRSD") def magic_word_authenticator(sock): magic = sock.recv(len(CONF.rpc_settings.magic_word)).decode() if magic != CONF.rpc_settings.magic_word: - raise AuthenticationError(f"wrong magic word {magic}") + raise AuthenticationError( + f"wrong magic word passed in '{magic}'" + f" != '{CONF.rpc_settings.magic_word}'", + ) return sock, None diff --git a/aprsd/threads/rx.py b/aprsd/threads/rx.py index dec146e..1cfbd30 100644 --- a/aprsd/threads/rx.py +++ b/aprsd/threads/rx.py @@ -25,6 +25,7 @@ class APRSDRXThread(APRSDThread): client.factory.create().client.stop() def loop(self): + LOG.info(f"APRSDRXThread Loop {self._client}:{self._client.client}") # setup the consumer of messages and block until a messages try: # This will register a packet consumer with aprslib