Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions synapse/handlers/worker_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@


logger = logging.getLogger(__name__)
_LOCK_RETRY_CAP_SECS = Duration(minutes=10).as_secs()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There is already a PR to address this kind of thing: #19394

🤔 I think we can continue with the other PR which is a bit more fleshed out and is currently stuck at the stage of the review being addressed.


# This lock is used to avoid creating an event while we are purging the room.
# We take a read lock when creating an event, and a write one when purging a room.
Expand Down Expand Up @@ -274,11 +275,11 @@ async def __aexit__(
return r

def _get_next_retry_interval(self) -> float:
next = self._retry_interval
self._retry_interval = max(5, next * 2)
if self._retry_interval > Duration(minutes=10).as_secs(): # >7 iterations
prev = self._retry_interval
self._retry_interval = min(_LOCK_RETRY_CAP_SECS, max(5, prev * 2))
if self._retry_interval == _LOCK_RETRY_CAP_SECS and prev < _LOCK_RETRY_CAP_SECS:
logger.warning(
"Lock timeout is getting excessive: %ss. There may be a deadlock.",
"Lock timeout hit cap of %ss. There may be a deadlock.",
self._retry_interval,
)
return next * random.uniform(0.9, 1.1)
Expand Down Expand Up @@ -361,11 +362,11 @@ async def __aexit__(
return r

def _get_next_retry_interval(self) -> float:
next = self._retry_interval
self._retry_interval = max(5, next * 2)
if self._retry_interval > Duration(minutes=10).as_secs(): # >7 iterations
prev = self._retry_interval
self._retry_interval = min(_LOCK_RETRY_CAP_SECS, max(5, prev * 2))
if self._retry_interval == _LOCK_RETRY_CAP_SECS and prev < _LOCK_RETRY_CAP_SECS:
logger.warning(
"Lock timeout is getting excessive: %ss. There may be a deadlock.",
"Lock timeout hit cap of %ss. There may be a deadlock.",
self._retry_interval,
)
return next * random.uniform(0.9, 1.1)