check closed condition after aquiring the lock to avoid deadlocks
This commit is contained in:
parent
2ce7d943fa
commit
f3dcf5c320
@ -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})
|
||||||
|
@ -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,18 +138,21 @@ class WebSocketConnection(object):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
with self.sendLock:
|
with self.sendLock:
|
||||||
for chunk in chunks(data_to_send, 1024):
|
if not self.open:
|
||||||
(_, write, _) = select.select([], [self.handler.wfile], [], 10)
|
logger.warning("_sendBytes() after connection was closed, ignoring")
|
||||||
if self.handler.wfile in write:
|
else:
|
||||||
written = self.handler.wfile.write(chunk)
|
for chunk in chunks(data_to_send, 1024):
|
||||||
if written != len(chunk):
|
(_, write, _) = select.select([], [self.handler.wfile], [], 10)
|
||||||
logger.error("incomplete write! closing socket!")
|
if self.handler.wfile in write:
|
||||||
|
written = self.handler.wfile.write(chunk)
|
||||||
|
if written != len(chunk):
|
||||||
|
logger.error("incomplete write! closing socket!")
|
||||||
|
self.close()
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
logger.debug("socket not returned from select; closing")
|
||||||
self.close()
|
self.close()
|
||||||
break
|
break
|
||||||
else:
|
|
||||||
logger.debug("socket not returned from select; closing")
|
|
||||||
self.close()
|
|
||||||
break
|
|
||||||
# these exception happen when the socket is closed
|
# these exception happen when the socket is closed
|
||||||
except OSError:
|
except OSError:
|
||||||
logger.exception("OSError while writing data")
|
logger.exception("OSError while writing data")
|
||||||
@ -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()
|
||||||
|
Loading…
Reference in New Issue
Block a user