From 3b94e40cc882ac2728fa8f053e45ac669e2d7fa2 Mon Sep 17 00:00:00 2001 From: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com> Date: Fri, 13 Jun 2025 12:36:21 +0100 Subject: [PATCH] Fix typo of Math.pow, `^` -> `**` (#18543) --- changelog.d/18543.bugfix | 1 + synapse/app/phone_stats_home.py | 4 +--- synapse/handlers/worker_lock.py | 5 +++-- synapse/util/constants.py | 20 ++++++++++++++++++++ 4 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 changelog.d/18543.bugfix create mode 100644 synapse/util/constants.py diff --git a/changelog.d/18543.bugfix b/changelog.d/18543.bugfix new file mode 100644 index 000000000..3db7b04a5 --- /dev/null +++ b/changelog.d/18543.bugfix @@ -0,0 +1 @@ +Fix an issue where "Lock timeout is getting excessive" warnings would be logged even when the lock timeout was <10 minutes. \ No newline at end of file diff --git a/synapse/app/phone_stats_home.py b/synapse/app/phone_stats_home.py index 9cd2e1b71..7e8c7cf37 100644 --- a/synapse/app/phone_stats_home.py +++ b/synapse/app/phone_stats_home.py @@ -28,15 +28,13 @@ from prometheus_client import Gauge from synapse.metrics.background_process_metrics import wrap_as_background_process from synapse.types import JsonDict +from synapse.util.constants import ONE_HOUR_SECONDS, ONE_MINUTE_SECONDS if TYPE_CHECKING: from synapse.server import HomeServer logger = logging.getLogger("synapse.app.homeserver") -ONE_MINUTE_SECONDS = 60 -ONE_HOUR_SECONDS = 60 * ONE_MINUTE_SECONDS - MILLISECONDS_PER_SECOND = 1000 INITIAL_DELAY_BEFORE_FIRST_PHONE_HOME_SECONDS = 5 * ONE_MINUTE_SECONDS diff --git a/synapse/handlers/worker_lock.py b/synapse/handlers/worker_lock.py index b36f7bd5f..3077e9e46 100644 --- a/synapse/handlers/worker_lock.py +++ b/synapse/handlers/worker_lock.py @@ -44,6 +44,7 @@ from synapse.logging.opentracing import start_active_span from synapse.metrics.background_process_metrics import wrap_as_background_process from synapse.storage.databases.main.lock import Lock, LockStore from synapse.util.async_helpers import timeout_deferred +from synapse.util.constants import ONE_MINUTE_SECONDS if TYPE_CHECKING: from synapse.logging.opentracing import opentracing @@ -272,7 +273,7 @@ class WaitingLock: def _get_next_retry_interval(self) -> float: next = self._retry_interval self._retry_interval = max(5, next * 2) - if self._retry_interval > 5 * 2 ^ 7: # ~10 minutes + if self._retry_interval > 10 * ONE_MINUTE_SECONDS: # >7 iterations logger.warning( "Lock timeout is getting excessive: %ss. There may be a deadlock.", self._retry_interval, @@ -352,7 +353,7 @@ class WaitingMultiLock: def _get_next_retry_interval(self) -> float: next = self._retry_interval self._retry_interval = max(5, next * 2) - if self._retry_interval > 5 * 2 ^ 7: # ~10 minutes + if self._retry_interval > 10 * ONE_MINUTE_SECONDS: # >7 iterations logger.warning( "Lock timeout is getting excessive: %ss. There may be a deadlock.", self._retry_interval, diff --git a/synapse/util/constants.py b/synapse/util/constants.py new file mode 100644 index 000000000..998601714 --- /dev/null +++ b/synapse/util/constants.py @@ -0,0 +1,20 @@ +# +# This file is licensed under the Affero General Public License (AGPL) version 3. +# +# Copyright (C) 2025 New Vector, Ltd +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# See the GNU Affero General Public License for more details: +# . +# + +# Time-based constants. +# +# Laying these out incrementally, even if only some are required, helps with +# readability and catching bugs. +ONE_MINUTE_SECONDS = 60 +ONE_HOUR_SECONDS = 60 * ONE_MINUTE_SECONDS