From a8ba43308e601ffeae9dabccf4f9b7432ea6a868 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 9 Jul 2020 14:00:36 +0200 Subject: [PATCH 01/11] =?UTF-8?q?=F0=9F=90=9B=20Don't=20drop=20state=20mes?= =?UTF-8?q?sages=20due=20to=20rate=20limits?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead hold them back until the next slot. Otherwise we might never get the final switch to Offline as after that there are no current data upgrades anymore. --- src/octoprint/printer/standard.py | 4 +++- src/octoprint/server/util/sockjs.py | 29 ++++++++++++++++++++--------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/octoprint/printer/standard.py b/src/octoprint/printer/standard.py index 3a8779071..63b47c7d5 100644 --- a/src/octoprint/printer/standard.py +++ b/src/octoprint/printer/standard.py @@ -1505,7 +1505,9 @@ class StateMonitor(object): self._last_update = monotonic_time() self._change_event.clear() except Exception: - logging.getLogger(__name__).exception("Looks like something crashed inside the state update worker. Please report this on the OctoPrint issue tracker (make sure to include logs!)") + logging.getLogger(__name__).exception("Looks like something crashed inside the state update worker. " + "Please report this on the OctoPrint issue tracker (make sure " + "to include logs!)") def get_current_data(self): with self._progress_lock: diff --git a/src/octoprint/server/util/sockjs.py b/src/octoprint/server/util/sockjs.py index 5f019ada1..7c40aa8ee 100644 --- a/src/octoprint/server/util/sockjs.py +++ b/src/octoprint/server/util/sockjs.py @@ -117,9 +117,12 @@ class PrinterStateConnection(octoprint.vendor.sockjs.tornado.SockJSConnection, self._remoteAddress = None self._user = self._userManager.anonymous_user_factory() - self._throttleFactor = 1 - self._lastCurrent = 0 - self._baseRateLimit = 0.5 + self._throttle_factor = 1 + self._last_current = 0 + self._base_rate_limit = 0.5 + + self._held_back_current = None + self._held_back_mutex = threading.RLock() self._register_hooks = self._pluginManager.get_hooks("octoprint.server.sockjs.register") self._authed_hooks = self._pluginManager.get_hooks("octoprint.server.sockjs.authed") @@ -222,18 +225,26 @@ class PrinterStateConnection(octoprint.vendor.sockjs.tornado.SockJSConnection, except ValueError: self._logger.warning("Got invalid throttle factor from client {}, ignoring: {!r}".format(self._remoteAddress, message["throttle"])) else: - self._throttleFactor = throttle - self._logger.debug("Set throttle factor for client {} to {}".format(self._remoteAddress, self._throttleFactor)) + self._throttle_factor = throttle + self._logger.debug("Set throttle factor for client {} to {}".format(self._remoteAddress, self._throttle_factor)) def on_printer_send_current_data(self, data): if not self._user.has_permission(Permissions.STATUS): return # make sure we rate limit the updates according to our throttle factor - now = time.time() - if now < self._lastCurrent + self._baseRateLimit * self._throttleFactor: - return - self._lastCurrent = now + with self._held_back_mutex: + if self._held_back_current is not None: + self._held_back_current.cancel() + self._held_back_current = None + + now = time.time() + delta = self._last_current + self._base_rate_limit * self._throttle_factor - now + if delta > 0: + self._held_back_current = threading.Timer(delta, lambda: self.on_printer_send_current_data(data)) + return + + self._last_current = now # add current temperature, log and message backlogs to sent data with self._temperatureBacklogMutex: From 6083943e03d704734cef9c4fab26ed55d86833d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 9 Jul 2020 15:41:46 +0200 Subject: [PATCH 02/11] =?UTF-8?q?=F0=9F=9A=B8=20Improve=20disconnect=20res?= =?UTF-8?q?ponse=20while=20not=20operational?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We don't want to try to send our beforeDisconnect script if we aren't properly connected, as that will severely delay Disconnect execution, so we now limit that to operational states and thus allow a quick(er) connection abort during auto detection or connection attempt. --- src/octoprint/util/comm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index 7c33d6a56..872c22fdb 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -959,7 +959,7 @@ class MachineCom(object): self._send_queue_active = False if self._serial is not None: - if not is_error: + if not is_error and self._state in self.OPERATIONAL_STATES: self.sendGcodeScript("beforePrinterDisconnected") if wait: if timeout is not None: From 9dd1e95eae86879b5a86624644caec7007be8968 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Fri, 24 Jul 2020 18:11:31 +0200 Subject: [PATCH 03/11] =?UTF-8?q?=F0=9F=90=9B=20Fix=20a=20potential=20race?= =?UTF-8?q?=20condition?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the comm layer starts sending state changes (e.g. to auto detect) before the constructor returns, self._comm in the printer interface is still None and thus states can't be decoded. Probably part of #3653 --- src/octoprint/printer/standard.py | 1 + src/octoprint/util/comm.py | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/octoprint/printer/standard.py b/src/octoprint/printer/standard.py index 63b47c7d5..01901dfb2 100644 --- a/src/octoprint/printer/standard.py +++ b/src/octoprint/printer/standard.py @@ -267,6 +267,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): logging.getLogger("SERIAL").info("serial.log is currently not enabled, you can enable it via Settings > Serial Connection > Log communication to serial.log") self._comm = comm.MachineCom(port, baudrate, callbackObject=self, printerProfileManager=self._printerProfileManager) + self._comm.start() def disconnect(self, *args, **kwargs): """ diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index 872c22fdb..d159fec24 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -648,12 +648,17 @@ class MachineCom(object): self._monitoring_active = True self.monitoring_thread = threading.Thread(target=self._monitor, name="comm._monitor") self.monitoring_thread.daemon = True - self.monitoring_thread.start() # sending thread self._send_queue_active = True self.sending_thread = threading.Thread(target=self._send_loop, name="comm.sending_thread") self.sending_thread.daemon = True + + def start(self): + # doing this here instead of __init__ combats a race condition where + # self._comm in the printer interface is still None on first pushs from + # the comm layer during detection + self.monitoring_thread.start() self.sending_thread.start() def __del__(self): From f1d4cb670a3ae29bebd7ad8373e8ca072caf033f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 27 Jul 2020 11:30:58 +0200 Subject: [PATCH 04/11] =?UTF-8?q?=F0=9F=90=9B=20Fix=20held=20back=20messag?= =?UTF-8?q?es=20not=20actually=20being=20sent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Probably part of #3653 --- src/octoprint/server/util/sockjs.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/octoprint/server/util/sockjs.py b/src/octoprint/server/util/sockjs.py index 7c40aa8ee..3848d8298 100644 --- a/src/octoprint/server/util/sockjs.py +++ b/src/octoprint/server/util/sockjs.py @@ -242,6 +242,7 @@ class PrinterStateConnection(octoprint.vendor.sockjs.tornado.SockJSConnection, delta = self._last_current + self._base_rate_limit * self._throttle_factor - now if delta > 0: self._held_back_current = threading.Timer(delta, lambda: self.on_printer_send_current_data(data)) + self._held_back_current.start() return self._last_current = now From 5246e2ccb46931a07ace169fa2eda02afeeb3cf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 27 Jul 2020 11:31:37 +0200 Subject: [PATCH 05/11] =?UTF-8?q?=F0=9F=90=9B=20Fix=20for=20some=20bugs=20?= =?UTF-8?q?in=20auto=20detection?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Probably related to #3653 --- src/octoprint/util/comm.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index d159fec24..6547e53a8 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -2408,19 +2408,27 @@ class MachineCom(object): self._detection_candidates)))) def attempt_handshake(): - timeout = self._get_communication_timeout_interval() - if self._serial.timeout != timeout: - self._serial.timeout = timeout - self._timeout = self._ok_timeout = monotonic_time() + timeout - - log("Handshake attempt #{} with timeout {}s".format(self._detection_retry + 1, timeout)) - self._detection_retry += 1 - self._do_send_without_checksum(b"", log=False) # new line to reset things - self.sayHello(tags={"trigger:detection", }) + timeout = self._get_communication_timeout_interval() + + log("Handshake attempt #{} with timeout {}s".format(self._detection_retry, timeout)) + try: + if self._serial.timeout != timeout: + self._serial.timeout = timeout + self._timeout = self._ok_timeout = monotonic_time() + timeout + except Exception: + self._log("Unexpected error while setting timeout {}: {}".format(timeout, get_exception_string())) + self._logger.exception("Unexpected error while setting timeout {}".format(timeout)) + else: + self._do_send_without_checksum(b"", log=False) # new line to reset things + self.sayHello(tags={"trigger:detection", }) while len(self._detection_candidates) > 0 or self._detection_retry < self.DETECTION_RETRIES: if self._detection_retry < self.DETECTION_RETRIES: + if self._serial is None: + self._detection_retry = self.DETECTION_RETRIES + continue + attempt_handshake() return From 0188745d05549ce5776843734968973a9166c11b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 27 Jul 2020 12:08:39 +0200 Subject: [PATCH 06/11] =?UTF-8?q?=F0=9F=90=9B=20Fix=20500=20on=20/api/file?= =?UTF-8?q?s/local?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #3655 --- src/octoprint/server/api/files.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/octoprint/server/api/files.py b/src/octoprint/server/api/files.py index 26b52627b..abec775a0 100644 --- a/src/octoprint/server/api/files.py +++ b/src/octoprint/server/api/files.py @@ -63,7 +63,12 @@ def _create_lastmodified(path, recursive): return max(lms) else: - storage, path_in_storage = path.split("/", 1) + if "/" in path: + storage, path_in_storage = path.split("/", 1) + else: + storage = path + path_in_storage = None + try: return fileManager.last_modified(storage, path=path_in_storage, recursive=recursive) except Exception: From 0cfc08748b2e21774318d0f7ed217709d13a0b78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 27 Jul 2020 15:59:47 +0200 Subject: [PATCH 07/11] =?UTF-8?q?=F0=9F=90=9B=20Set=20closed=20state=20eve?= =?UTF-8?q?n=20if=20not=20yet=20open?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit And also ensure we only attempt serial auto detect if we are still in the correct state for it. Closes #3653 --- src/octoprint/util/comm.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index 6547e53a8..058ab725e 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -995,15 +995,17 @@ class MachineCom(object): self._logger.exception("Error while trying to close serial port") is_error = True - # if we are printing, this will also make sure of firing PRINT_FAILED - if is_error: - self._changeState(self.STATE_CLOSED_WITH_ERROR) - else: - self._changeState(self.STATE_CLOSED) else: deactivate_monitoring_and_send_queue() + self._serial = None + # if we are printing, this will also make sure of firing PRINT_FAILED + if is_error: + self._changeState(self.STATE_CLOSED_WITH_ERROR) + else: + self._changeState(self.STATE_CLOSED) + if settings().getBoolean(["feature", "sdSupport"]): self._sdFileList = [] @@ -1682,6 +1684,10 @@ class MachineCom(object): self._changeState(self.STATE_DETECT_SERIAL) self._perform_detection_step(init=True) + if not self._state in (self.STATE_CONNECTING, self.STATE_DETECT_SERIAL): + # we got cancelled during connection, bail + return + # Start monitoring the serial port self._log("Connected to: %s, starting monitor" % self._serial) @@ -2424,6 +2430,9 @@ class MachineCom(object): self.sayHello(tags={"trigger:detection", }) while len(self._detection_candidates) > 0 or self._detection_retry < self.DETECTION_RETRIES: + if self._state not in (self.STATE_DETECT_SERIAL,): + return + if self._detection_retry < self.DETECTION_RETRIES: if self._serial is None: self._detection_retry = self.DETECTION_RETRIES @@ -2753,7 +2762,9 @@ class MachineCom(object): serial_obj.close() serial_obj.parity = serial.PARITY_NONE - serial_obj.open() + #serial_obj.open() + time.sleep(5.0) + raise OSError(22, 'The semaphore timeout period has expired.', None, 121) # Set close_exec flag on serial handle, see #3212 if hasattr(serial_obj, "fd"): From 57b085ff5c84a6c1303b56091944728bc8aeac71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 27 Jul 2020 16:00:39 +0200 Subject: [PATCH 08/11] =?UTF-8?q?=F0=9F=90=9B=20Remove=20accidentally=20co?= =?UTF-8?q?mmitted=20debug=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See #3653 --- src/octoprint/util/comm.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index 058ab725e..906c0820e 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -2762,9 +2762,7 @@ class MachineCom(object): serial_obj.close() serial_obj.parity = serial.PARITY_NONE - #serial_obj.open() - time.sleep(5.0) - raise OSError(22, 'The semaphore timeout period has expired.', None, 121) + serial_obj.open() # Set close_exec flag on serial handle, see #3212 if hasattr(serial_obj, "fd"): From ab8ad72bc3d9536a8d18007b528a46a75071aaa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 28 Jul 2020 19:33:48 +0200 Subject: [PATCH 09/11] =?UTF-8?q?=F0=9F=A5=85=20PMGR:=20Ensure=20validity?= =?UTF-8?q?=20of=20latest=20release=20data?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #3661 --- .../pluginmanager/templates/pluginmanager_settings.jinja2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octoprint/plugins/pluginmanager/templates/pluginmanager_settings.jinja2 b/src/octoprint/plugins/pluginmanager/templates/pluginmanager_settings.jinja2 index a774980da..39457dacf 100644 --- a/src/octoprint/plugins/pluginmanager/templates/pluginmanager_settings.jinja2 +++ b/src/octoprint/plugins/pluginmanager/templates/pluginmanager_settings.jinja2 @@ -268,7 +268,7 @@ - () + () From 458ab91f915307857941f839a1b743430b8786a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 29 Jul 2020 10:35:49 +0200 Subject: [PATCH 10/11] =?UTF-8?q?=F0=9F=94=96=20Preparing=20release=20of?= =?UTF-8?q?=201.4.1rc4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SUPPORTERS.md | 3 +-- src/octoprint/plugins/errortracking/__init__.py | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/SUPPORTERS.md b/SUPPORTERS.md index 8876adb44..d7304f123 100644 --- a/SUPPORTERS.md +++ b/SUPPORTERS.md @@ -17,7 +17,6 @@ thanks to everyone who contributed! * D Brian Kimmel * DeltaMaker 3D Printers * Dennis Breining - * Dorian Gray * Eric Betts * Ernesto Martinez * Franziska Kunsmann @@ -66,4 +65,4 @@ thanks to everyone who contributed! * Sven Mueller * Ulrich Kempken -and 1886 more wonderful people pledging on the [Patreon campaign](https://patreon.com/foosel) or via [Github Sponsors](https://github.com/users/foosel/sponsorship)! \ No newline at end of file +and 1932 more wonderful people pledging on the [Patreon campaign](https://patreon.com/foosel) or via [Github Sponsors](https://github.com/users/foosel/sponsorship)! \ No newline at end of file diff --git a/src/octoprint/plugins/errortracking/__init__.py b/src/octoprint/plugins/errortracking/__init__.py index 291d3b9fd..23e61d123 100644 --- a/src/octoprint/plugins/errortracking/__init__.py +++ b/src/octoprint/plugins/errortracking/__init__.py @@ -13,8 +13,8 @@ from octoprint.util.version import get_octoprint_version_string, is_released_oct from flask import jsonify from flask_babel import gettext -SENTRY_URL_SERVER = "https://829e2245ec4d4693a0b708523004c4eb@o118517.ingest.sentry.io/1373987" -SENTRY_URL_COREUI = "https://fcbbcf95f5514b59866c5e7360fba1fe@o118517.ingest.sentry.io/1374096" +SENTRY_URL_SERVER = "https://912dd511a2274c6f99705d926c2b5126@o118517.ingest.sentry.io/1373987" +SENTRY_URL_COREUI = "https://572ed52f42d241c484db1c741e3c131e@o118517.ingest.sentry.io/1374096" SETTINGS_DEFAULTS = dict(enabled=False, enabled_unreleased=False, From 57b8d0b88e40bd7a0a8f132870993b667ea1b24c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 29 Jul 2020 12:20:33 +0200 Subject: [PATCH 11/11] =?UTF-8?q?=F0=9F=94=96=20staging/maintenance=20is?= =?UTF-8?q?=20now=201.4.1rc5.dev?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .versioneer-lookup | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.versioneer-lookup b/.versioneer-lookup index f86098820..462bf71ee 100644 --- a/.versioneer-lookup +++ b/.versioneer-lookup @@ -24,10 +24,10 @@ maintenance 1.4.1 2da7aa358d950b4567aaab8f18d6b5779193e077 pep440-dev fix/.* 1.4.1 2da7aa358d950b4567aaab8f18d6b5779193e077 pep440-dev improve/.* 1.4.1 2da7aa358d950b4567aaab8f18d6b5779193e077 pep440-dev -# staging/maintenance is currently the branch for preparation of 1.4.1rc4 +# staging/maintenance is currently the branch for preparation of 1.4.1rc5 # so is regressionfix/... -staging/maintenance 1.4.1rc4 650d54d1885409fa1d411eb54b9e8c7ff428910f pep440-dev -regressionfix/.* 1.4.1rc4 650d54d1885409fa1d411eb54b9e8c7ff428910f pep440-dev +staging/maintenance 1.4.1rc5 458ab91f915307857941f839a1b743430b8786a4 pep440-dev +regressionfix/.* 1.4.1rc5 458ab91f915307857941f839a1b743430b8786a4 pep440-dev # staging/devel is currently inactive (but has the 1.4.1rc4 namespace) staging/devel 1.4.1rc4 650d54d1885409fa1d411eb54b9e8c7ff428910f pep440-dev