Skip to content

Commit

Permalink
馃 Try up to three times to check for connectivity
Browse files Browse the repository at this point in the history
Apparently some machines out there are a bit flaky after boot and it can
take a bit for connectivity to work. As suggested by @fieldOfView in

  https://community.octoprint.org/t//177/9

we thus check connectivity three times in a row if negative before
reporting it as negative.
  • Loading branch information
foosel committed Jul 31, 2020
1 parent 65937a9 commit cae900b
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/octoprint/util/connectivity.py
Expand Up @@ -7,6 +7,7 @@

import threading
import logging
import time

from octoprint.util.net import server_reachable, resolve_host

Expand Down Expand Up @@ -171,16 +172,26 @@ def _perform_check(self):
self._logger.debug("Checking against {}:{} if we are online...".format(self._host, self._port))

old_value = self._online
self._connection_working = server_reachable(self._host, port=self._port)

if self._name:
if self._connection_working:
self._logger.debug("Checking if we can resolve {}...".format(self._name))
self._resolution_working = len(resolve_host(self._name)) > 0
for _ in range(3):
connection_working = server_reachable(self._host, port=self._port)

if self._name:
if connection_working:
self._logger.debug("Checking if we can resolve {}...".format(self._name))
resolution_working = len(resolve_host(self._name)) > 0
else:
resolution_working = False
else:
self._resolution_working = False
else:
self._resolution_working = True
resolution_working = True

if not (connection_working and resolution_working):
# retry up to 3 times
time.sleep(1.0)
continue

self._connection_working = connection_working
self._resolution_working = resolution_working

if old_value != self._online:
self._trigger_change(old_value, self._online)
Expand Down

1 comment on commit cae900b

@GitIssueBot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been mentioned on OctoPrint Community Forum. There might be relevant details there:

https://community.octoprint.org/t/octoprint-claims-to-not-have-a-connection-to-the-internet-but-it-does/177/10

Please sign in to comment.