Skip to content

Commit

Permalink
Set a longer during NTP requests for increased reliability
Browse files Browse the repository at this point in the history
A follow-up to #256. Setting a longer timeout allows for more time for
NTP requests to go through, making the requests more reliable (the goal
is to use the system's time as little as possible).
  • Loading branch information
jdholtz committed May 13, 2024
1 parent 3a1dee1 commit 1f2149f
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ def get_current_time() -> datetime:
c = ntplib.NTPClient()

try:
response = c.request(NTP_SERVER, version=3)
# Set a longer timeout to make the request more reliable
response = c.request(NTP_SERVER, version=3, timeout=10)
except (socket.gaierror, ntplib.NTPException):
logger.debug("Error requesting time from NTP server. Using local time")
return datetime.now(timezone.utc)
Expand Down

0 comments on commit 1f2149f

Please sign in to comment.