Skip to content

Commit 3b94e40

Browse files
Fix typo of Math.pow, ^ -> ** (element-hq#18543)
1 parent 6b1e3c9 commit 3b94e40

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

changelog.d/18543.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix an issue where "Lock timeout is getting excessive" warnings would be logged even when the lock timeout was <10 minutes.

synapse/app/phone_stats_home.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,13 @@
2828

2929
from synapse.metrics.background_process_metrics import wrap_as_background_process
3030
from synapse.types import JsonDict
31+
from synapse.util.constants import ONE_HOUR_SECONDS, ONE_MINUTE_SECONDS
3132

3233
if TYPE_CHECKING:
3334
from synapse.server import HomeServer
3435

3536
logger = logging.getLogger("synapse.app.homeserver")
3637

37-
ONE_MINUTE_SECONDS = 60
38-
ONE_HOUR_SECONDS = 60 * ONE_MINUTE_SECONDS
39-
4038
MILLISECONDS_PER_SECOND = 1000
4139

4240
INITIAL_DELAY_BEFORE_FIRST_PHONE_HOME_SECONDS = 5 * ONE_MINUTE_SECONDS

synapse/handlers/worker_lock.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
from synapse.metrics.background_process_metrics import wrap_as_background_process
4545
from synapse.storage.databases.main.lock import Lock, LockStore
4646
from synapse.util.async_helpers import timeout_deferred
47+
from synapse.util.constants import ONE_MINUTE_SECONDS
4748

4849
if TYPE_CHECKING:
4950
from synapse.logging.opentracing import opentracing
@@ -272,7 +273,7 @@ async def __aexit__(
272273
def _get_next_retry_interval(self) -> float:
273274
next = self._retry_interval
274275
self._retry_interval = max(5, next * 2)
275-
if self._retry_interval > 5 * 2 ^ 7: # ~10 minutes
276+
if self._retry_interval > 10 * ONE_MINUTE_SECONDS: # >7 iterations
276277
logger.warning(
277278
"Lock timeout is getting excessive: %ss. There may be a deadlock.",
278279
self._retry_interval,
@@ -352,7 +353,7 @@ async def __aexit__(
352353
def _get_next_retry_interval(self) -> float:
353354
next = self._retry_interval
354355
self._retry_interval = max(5, next * 2)
355-
if self._retry_interval > 5 * 2 ^ 7: # ~10 minutes
356+
if self._retry_interval > 10 * ONE_MINUTE_SECONDS: # >7 iterations
356357
logger.warning(
357358
"Lock timeout is getting excessive: %ss. There may be a deadlock.",
358359
self._retry_interval,

synapse/util/constants.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#
2+
# This file is licensed under the Affero General Public License (AGPL) version 3.
3+
#
4+
# Copyright (C) 2025 New Vector, Ltd
5+
#
6+
# This program is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU Affero General Public License as
8+
# published by the Free Software Foundation, either version 3 of the
9+
# License, or (at your option) any later version.
10+
#
11+
# See the GNU Affero General Public License for more details:
12+
# <https://www.gnu.org/licenses/agpl-3.0.html>.
13+
#
14+
15+
# Time-based constants.
16+
#
17+
# Laying these out incrementally, even if only some are required, helps with
18+
# readability and catching bugs.
19+
ONE_MINUTE_SECONDS = 60
20+
ONE_HOUR_SECONDS = 60 * ONE_MINUTE_SECONDS

0 commit comments

Comments
 (0)