Fix race condition in resend handling
Could be triggered if two resend requests without an ok were directly following each other, causing a resend ok timer to be triggered for each and a consequent attempt to process the same resend status again. Should fix #2632
This commit is contained in:
1 parent
4f1b781219
commit
d124efdb71
1 file changed
+19
-10
+19
-10
@@ -1480,6 +1480,12 @@ class MachineCom(object):
|
||||
if self._dwelling_until and now > self._dwelling_until:
|
||||
self._dwelling_until = False
|
||||
|
||||
if self._resend_ok_timer and line and not line.startswith("ok"):
|
||||
# we got anything but an ok after a resend request - this means the ok after the resend request
|
||||
# was in fact missing and we now need to trigger the timer
|
||||
self._resend_ok_timer.cancel()
|
||||
self._resendSimulateOk()
|
||||
|
||||
##~~ busy protocol handling
|
||||
if line.startswith("echo:busy:") or line.startswith("busy:"):
|
||||
# reset the ok timeout, the regular comm timeout has already been reset
|
||||
@@ -2017,11 +2023,12 @@ class MachineCom(object):
|
||||
|
||||
# process queues ongoing resend requests and queues if we are operational
|
||||
|
||||
if self._resendDelta is not None:
|
||||
self._resendNextCommand()
|
||||
else:
|
||||
self._resendActive = False
|
||||
self._continue_sending()
|
||||
with self._sendingLock: # prevent concurrency due to resend_ok_timers
|
||||
if self._resendDelta is not None:
|
||||
self._resendNextCommand()
|
||||
else:
|
||||
self._resendActive = False
|
||||
self._continue_sending()
|
||||
|
||||
return
|
||||
|
||||
@@ -2659,13 +2666,15 @@ class MachineCom(object):
|
||||
if self._trigger_ok_after_resend == "always":
|
||||
self._handle_ok()
|
||||
elif self._trigger_ok_after_resend == "detect":
|
||||
def process():
|
||||
self._resend_ok_timer = None
|
||||
self._handle_ok()
|
||||
self._logger.info("Firmware didn't send an 'ok' with their resend request. That's a known bug with some firmware variants out there. Simulating an ok to continue...")
|
||||
self._resend_ok_timer = threading.Timer(self._timeout_intervals.get("resendOk", 1.0), process)
|
||||
self._resend_ok_timer = threading.Timer(self._timeout_intervals.get("resendOk", 1.0), self._resendSimulateOk)
|
||||
self._resend_ok_timer.start()
|
||||
|
||||
def _resendSimulateOk(self):
|
||||
self._resend_ok_timer = None
|
||||
self._handle_ok()
|
||||
self._logger.info("Firmware didn't send an 'ok' with their resend request. That's a known bug "
|
||||
"with some firmware variants out there. Simulating an ok to continue...")
|
||||
|
||||
def _resendSameCommand(self):
|
||||
return self._resendNextCommand(again=True)
|
||||
|
||||
|
||||
Reference in new issue
Block a user