☔ Detect endless resend requests & abort
If the printer keeps requesting the same line over and over again, something is either seriously wrong with the line or with the connection In any case, log an error and disconnect.
This commit is contained in:
1 parent
e029f33901
commit
81342acccc
4 files changed
+28
-1
No files matched your search
@@ -146,6 +146,7 @@ class VirtualPrinter(object):
|
||||
self._debug_sleep = None
|
||||
self._sleepAfterNext = dict()
|
||||
self._sleepAfter = dict()
|
||||
self._rerequest_last = False
|
||||
|
||||
self._dont_answer = False
|
||||
|
||||
@@ -364,6 +365,9 @@ class VirtualPrinter(object):
|
||||
elif isinstance(prepared, basestring):
|
||||
self._send(prepared)
|
||||
continue
|
||||
elif self._rerequest_last:
|
||||
self._triggerResend(actual=linenumber)
|
||||
continue
|
||||
else:
|
||||
self.lastN = linenumber
|
||||
data = data.split(None, 1)[1].strip()
|
||||
@@ -753,6 +757,8 @@ class VirtualPrinter(object):
|
||||
prepare_ok <broken ok>
|
||||
| Will cause <broken ok> to be enqueued for use,
|
||||
| will be used instead of actual "ok"
|
||||
rerequest_last
|
||||
| Will cause the last line number + 1 to be rerequest add infinitum
|
||||
|
||||
# Reply Timing / Sleeping
|
||||
|
||||
@@ -814,6 +820,9 @@ class VirtualPrinter(object):
|
||||
elif data == "go_awol":
|
||||
self._send("// Going AWOL")
|
||||
self._debug_awol = True
|
||||
elif data == "rerequest_last":
|
||||
self._send("// Entering rerequest loop")
|
||||
self._rerequest_last = True
|
||||
elif data == "cancel_sd":
|
||||
if self._sdPrinting and self._sdPrinter:
|
||||
self._pauseSdPrint()
|
||||
|
||||
@@ -145,6 +145,7 @@ default_settings = {
|
||||
"firmwareDetection": True,
|
||||
"blockWhileDwelling": False,
|
||||
"useParityWorkaround": "detect",
|
||||
"maxConsecutiveResends": 10,
|
||||
|
||||
"capabilities": {
|
||||
"autoreport_temp": True,
|
||||
|
||||
@@ -266,6 +266,7 @@ function DataUpdater(allViewModels, connectCallback, disconnectCallback) {
|
||||
break;
|
||||
}
|
||||
case "resend":
|
||||
case "resend_loop":
|
||||
case "timeout": {
|
||||
title = gettext("Communication error");
|
||||
text = _.sprintf(gettext("There was a communication error while talking to your printer. Please consult the terminal output and octoprint.log for details. Error: %(error)s"), payload);
|
||||
|
||||
@@ -469,6 +469,10 @@ class MachineCom(object):
|
||||
self._lastResendNumber = None
|
||||
self._currentResendCount = 0
|
||||
|
||||
self._currentConsecutiveResendNumber = None
|
||||
self._currentConsecutiveResendCount = 0
|
||||
self._maxConsecutiveResends = settings().getInt(["serial", "maxConsecutiveResends"])
|
||||
|
||||
self._errorValue = ""
|
||||
|
||||
self._firmware_detection = settings().getBoolean(["serial", "firmwareDetection"])
|
||||
@@ -2910,13 +2914,25 @@ class MachineCom(object):
|
||||
self._currentResendCount += 1
|
||||
return True
|
||||
|
||||
if self._currentConsecutiveResendNumber == lineToResend:
|
||||
self._currentConsecutiveResendCount += 1
|
||||
if self._currentConsecutiveResendCount >= self._maxConsecutiveResends:
|
||||
# printer keeps requesting the same line again and again, something is severely broken here
|
||||
error_text = "Printer keeps requesting line {} again and again, communication stuck".format(lineToResend)
|
||||
self._log(error_text)
|
||||
self._logger.warn(error_text)
|
||||
self._trigger_error(error_text, "resend_loop")
|
||||
else:
|
||||
self._currentConsecutiveResendNumber = lineToResend
|
||||
self._currentConsecutiveResendCount = 0
|
||||
|
||||
self._resendActive = True
|
||||
self._resendDelta = resendDelta
|
||||
self._lastResendNumber = lineToResend
|
||||
self._currentResendCount = 0
|
||||
|
||||
if self._resendDelta > len(self._lastLines) or len(self._lastLines) == 0 or self._resendDelta < 0:
|
||||
error_text = "Printer requested line %d but no sufficient history is available, can't resend" % lineToResend
|
||||
error_text = "Printer requested line {} but no sufficient history is available, can't resend".format(lineToResend)
|
||||
self._log(error_text)
|
||||
self._logger.warn(error_text + ". Printer requested line {}, current line is {}, line history has {} entries.".format(lineToResend, self._currentLine, len(self._lastLines)))
|
||||
if self.isPrinting():
|
||||
|
||||
Reference in new issue
Block a user