From 50e491bab43ca4c6fa11165c3348f97cc482c17e Mon Sep 17 00:00:00 2001 From: Hemna Date: Tue, 2 Apr 2024 18:23:37 -0400 Subject: [PATCH] Lock around client reset We now have multiple places where we call reset in case a network connection fails, so now there is a mutex lock around the reset method. --- aprsd/client.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/aprsd/client.py b/aprsd/client.py index 77782f0..e3d2079 100644 --- a/aprsd/client.py +++ b/aprsd/client.py @@ -1,11 +1,13 @@ import abc import datetime import logging +import threading import time import aprslib from aprslib.exceptions import LoginError from oslo_config import cfg +import wrapt from aprsd import exception from aprsd.clients import aprsis, fake, kiss @@ -28,6 +30,10 @@ factory = None @singleton class APRSClientStats: + + lock = threading.Lock() + + @wrapt.synchronized(lock) def stats(self, serializable=False): client = factory.create() stats = { @@ -58,6 +64,7 @@ class Client: connected = False filter = None + lock = threading.Lock() def __new__(cls, *args, **kwargs): """This magic turns this into a singleton.""" @@ -97,6 +104,7 @@ class Client: packet_list.PacketList().tx(packet) self.client.send(packet) + @wrapt.synchronized(lock) def reset(self): """Call this to force a rebuild/reconnect.""" LOG.info("Resetting client connection.")