Skip to content

Commit

Permalink
Solving race condition causing interruption through out of lock modem…
Browse files Browse the repository at this point in the history
… closure
  • Loading branch information
JimCircadian committed Oct 17, 2024
1 parent 535cc66 commit c789a39
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
26 changes: 14 additions & 12 deletions pyremotenode/tasks/iridium.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def close(self):
if self._data and self._data.is_open:
logging.debug("Closing and removing modem serial connection")
self._data.close()
self._data = None
self._data = None

def get_iridium_system_time(self):
with self._thread_lock:
Expand Down Expand Up @@ -261,13 +261,13 @@ def run(self):
except Exception:
logging.exception("Modem inoperational or another error occurred")
finally:
self.close()
if modem_locked:
self.close()

try:
if modem_locked:
try:
self.modem_lock.release()
except RuntimeError:
logging.warning("Looks like the lock wasn't acquired, dealing with this...")
except RuntimeError:
logging.warning("Looks like the lock wasn't acquired, dealing with this...")

logging.debug("{} thread waiting...".format(self.__class__.__name__))
tm.sleep(self._modem_wait)
Expand Down Expand Up @@ -602,7 +602,7 @@ def _send_receive_messages(self, message, raw=False, dont_decode=False, timeout_
blocks) may contain numerous newlines, and hence read() must be used (with an excessive upper limit; the
maximum message size is ~2000 bytes), returning at the end of the configured timeout - make sure it is long enough!
"""
if not self._data.isOpen():
if self._data is None or not self._data.is_open:
raise ModemConnectionException('Cannot send message; data port is not open')
self._data.flushInput()
self._data.flushOutput()
Expand Down Expand Up @@ -896,21 +896,23 @@ def default_action(self,
try:
if modem.modem_lock.acquire(blocking=False):
modem_locked = True
logging.debug("Running MTMessageCheck initialisation")
modem.initialise_modem()

if modem.signal_check():
logging.debug("Running MTMessageCheck processing")
modem.process_sbd_message()
except ModemConnectionException:
logging.exception("Caught a modem exception running the regular task, abandoning")
except Exception:
logging.exception("Modem inoperational or another error occurred")
finally:
modem.close()
if modem_locked:
modem.close()

try:
if modem_locked:
try:
modem.modem_lock.release()
except RuntimeError:
logging.warning("Looks like the lock wasn't acquired, dealing with this...")
except RuntimeError:
logging.warning("Looks like the lock wasn't acquired, dealing with this...")

return BaseTask.OK
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"run_pyremotenode",
],
include_package_data = True,
version = '0.5.0a7-lpm',
version = '0.5.0a8-lpm',
author = 'James Byrne',
author_email = 'jambyr@bas.ac.uk',
url = 'http://www.github.com/antarctica/pyremotenode',
Expand Down

0 comments on commit c789a39

Please sign in to comment.