From ba145b3194ef8af1dd3f24b3167206f724fd04be Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Thu, 18 Jan 2024 22:04:42 -0800 Subject: [PATCH] diagnostics: Safely access results when showing notification It is best to have obtained the results lock when counting the severe failures in diagnostic results. Tests: - When some packages are outdated, notification is shown with warning severity. Signed-off-by: Sunil Mohan Adapa --- plinth/modules/diagnostics/__init__.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/plinth/modules/diagnostics/__init__.py b/plinth/modules/diagnostics/__init__.py index 5117cb20b..410963e65 100644 --- a/plinth/modules/diagnostics/__init__.py +++ b/plinth/modules/diagnostics/__init__.py @@ -271,19 +271,18 @@ def _run_diagnostics(): kvstore.set('diagnostics_results', json.dumps(results, cls=CheckJSONEncoder)) - issue_count = 0 - severity = 'warning' - for _app_id, app_data in results.items(): - if app_data['exception']: - issue_count += 1 - severity = 'error' - else: - for check in app_data['diagnosis']: - if check.result != Result.PASSED: - if check.result != Result.WARNING: - severity = 'error' - - issue_count += 1 + issue_count = 0 + severity = 'warning' + for _app_id, app_data in results.items(): + if app_data['exception']: + issue_count += 1 + severity = 'error' + else: + for check in app_data['diagnosis']: + if check.result != Result.PASSED: + issue_count += 1 + if check.result != Result.WARNING: + severity = 'error' if not issue_count: # Remove any previous notifications if there are no issues.