check closed condition after aquiring the lock to avoid deadlocks

This commit is contained in:
Jakob Ketterl 2022-01-05 17:55:46 +01:00
parent 2ce7d943fa
commit f3dcf5c320
2 changed files with 16 additions and 19 deletions

View File

@ -513,8 +513,6 @@ class DspManager(SdrSourceEventClient, ClientDemodulatorSecondaryDspEventClient)
self.sdrSource.addClient(self) self.sdrSource.addClient(self)
super().__init__()
def setSecondaryFftSize(self, size): def setSecondaryFftSize(self, size):
self.chain.setSecondaryFftSize(size) self.chain.setSecondaryFftSize(size)
self.handler.write_secondary_dsp_config({"secondary_fft_size": size}) self.handler.write_secondary_dsp_config({"secondary_fft_size": size})

View File

@ -30,10 +30,6 @@ class Drained(WebSocketException):
pass pass
class WebSocketClosed(WebSocketException):
pass
class Handler(ABC): class Handler(ABC):
@abstractmethod @abstractmethod
def handleTextMessage(self, connection, message: str): def handleTextMessage(self, connection, message: str):
@ -118,8 +114,6 @@ class WebSocketConnection(object):
return bytes([ws_first_byte, size]) return bytes([ws_first_byte, size])
def send(self, data): def send(self, data):
if not self.open:
raise WebSocketClosed()
# convenience # convenience
if type(data) == dict: if type(data) == dict:
# allow_nan = False disallows NaN and Infinty to be encoded. Browser JSON will not parse them anyway. # allow_nan = False disallows NaN and Infinty to be encoded. Browser JSON will not parse them anyway.
@ -144,6 +138,9 @@ class WebSocketConnection(object):
try: try:
with self.sendLock: with self.sendLock:
if not self.open:
logger.warning("_sendBytes() after connection was closed, ignoring")
else:
for chunk in chunks(data_to_send, 1024): for chunk in chunks(data_to_send, 1024):
(_, write, _) = select.select([], [self.handler.wfile], [], 10) (_, write, _) = select.select([], [self.handler.wfile], [], 10)
if self.handler.wfile in write: if self.handler.wfile in write:
@ -270,7 +267,9 @@ class WebSocketConnection(object):
def cancelPing(self): def cancelPing(self):
if self.pingTimer: if self.pingTimer:
self.pingTimer.cancel() old = self.pingTimer
self.pingTimer = None
old.cancel()
def resetPing(self): def resetPing(self):
self.cancelPing() self.cancelPing()