|
20 | 20 | #
|
21 | 21 | #
|
22 | 22 | import logging
|
| 23 | +from threading import Lock |
23 | 24 | from typing import (
|
24 | 25 | TYPE_CHECKING,
|
25 | 26 | AbstractSet,
|
@@ -1237,7 +1238,7 @@ def __init__(self, hs: "HomeServer", device_handler: DeviceHandler):
|
1237 | 1238 | )
|
1238 | 1239 |
|
1239 | 1240 | # Attempt to resync out of sync device lists every 30s.
|
1240 |
| - self._resync_retry_in_progress = False |
| 1241 | + self._resync_retry_lock = Lock() |
1241 | 1242 | self.clock.looping_call(
|
1242 | 1243 | run_as_background_process,
|
1243 | 1244 | 30 * 1000,
|
@@ -1419,13 +1420,9 @@ async def _maybe_retry_device_resync(self) -> None:
|
1419 | 1420 | """Retry to resync device lists that are out of sync, except if another retry is
|
1420 | 1421 | in progress.
|
1421 | 1422 | """
|
1422 |
| - if self._resync_retry_in_progress: |
| 1423 | + if self._resync_retry_lock.locked(): |
1423 | 1424 | return
|
1424 |
| - |
1425 |
| - try: |
1426 |
| - # Prevent another call of this function to retry resyncing device lists so |
1427 |
| - # we don't send too many requests. |
1428 |
| - self._resync_retry_in_progress = True |
| 1425 | + with self._resync_retry_lock: |
1429 | 1426 | # Get all of the users that need resyncing.
|
1430 | 1427 | need_resync = await self.store.get_user_ids_requiring_device_list_resync()
|
1431 | 1428 |
|
@@ -1465,9 +1462,6 @@ async def _maybe_retry_device_resync(self) -> None:
|
1465 | 1462 | user_id,
|
1466 | 1463 | e,
|
1467 | 1464 | )
|
1468 |
| - finally: |
1469 |
| - # Allow future calls to retry resyncinc out of sync device lists. |
1470 |
| - self._resync_retry_in_progress = False |
1471 | 1465 |
|
1472 | 1466 | async def multi_user_device_resync(
|
1473 | 1467 | self, user_ids: List[str], mark_failed_as_stale: bool = True
|
|
0 commit comments