Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 6525fd6

Browse files
author
David Robertson
authored
Log the details of background update failures (#16212)
1 parent ed5e8a7 commit 6525fd6

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

changelog.d/16212.misc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Log the details of background update failures.

synapse/storage/background_updates.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -405,14 +405,14 @@ async def run_background_updates(self, sleep: bool) -> None:
405405
try:
406406
result = await self.do_next_background_update(sleep)
407407
back_to_back_failures = 0
408-
except Exception:
408+
except Exception as e:
409+
logger.exception("Error doing update: %s", e)
409410
back_to_back_failures += 1
410411
if back_to_back_failures >= 5:
411412
self._aborted = True
412413
raise RuntimeError(
413414
"5 back-to-back background update failures; aborting."
414415
)
415-
logger.exception("Error doing update")
416416
else:
417417
if result:
418418
logger.info(

tests/storage/test_background_update.py

+23-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
14+
import logging
1515
from unittest.mock import AsyncMock, Mock
1616

1717
import yaml
@@ -330,6 +330,28 @@ async def update_short(progress: JsonDict, count: int) -> int:
330330
self.update_handler.side_effect = update_short
331331
self.get_success(self.updates.do_next_background_update(False))
332332

333+
def test_failed_update_logs_exception_details(self) -> None:
334+
needle = "RUH ROH RAGGY"
335+
336+
def failing_update(progress: JsonDict, count: int) -> int:
337+
raise Exception(needle)
338+
339+
self.update_handler.side_effect = failing_update
340+
self.update_handler.reset_mock()
341+
342+
self.get_success(
343+
self.store.db_pool.simple_insert(
344+
"background_updates",
345+
values={"update_name": "test_update", "progress_json": "{}"},
346+
)
347+
)
348+
349+
with self.assertLogs(level=logging.ERROR) as logs:
350+
# Expect a back-to-back RuntimeError to be raised
351+
self.get_failure(self.updates.run_background_updates(False), RuntimeError)
352+
353+
self.assertTrue(any(needle in log for log in logs.output), logs.output)
354+
333355

334356
class BackgroundUpdateControllerTestCase(unittest.HomeserverTestCase):
335357
def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer) -> None:

0 commit comments

Comments
 (0)