Browse Source

Merge pull request #348 from sbcrumb/fix/duplicate-error-notifications

Fix duplicate HMS error notifications from race condition
MartinNYHC 3 months ago
parent
commit
ac9bbc354a
1 changed files with 3 additions and 2 deletions
  1. 3 2
      backend/app/main.py

+ 3 - 2
backend/app/main.py

@@ -416,6 +416,9 @@ async def on_printer_status_change(printer_id: int, state: PrinterState):
         # Find new errors that haven't been notified yet
         # Find new errors that haven't been notified yet
         new_error_codes = current_error_codes - previously_notified
         new_error_codes = current_error_codes - previously_notified
 
 
+        # Update tracking immediately to prevent duplicate notifications from concurrent callbacks
+        _notified_hms_errors[printer_id] = current_error_codes
+
         if new_error_codes:
         if new_error_codes:
             # Get the actual new errors for the notification
             # Get the actual new errors for the notification
             # Filter to severity >= 2 (skip informational/status messages like H2D sends)
             # Filter to severity >= 2 (skip informational/status messages like H2D sends)
@@ -486,8 +489,6 @@ async def on_printer_status_change(printer_id: int, state: PrinterState):
             except Exception as e:
             except Exception as e:
                 logging.getLogger(__name__).warning(f"HMS error notification failed: {e}")
                 logging.getLogger(__name__).warning(f"HMS error notification failed: {e}")
 
 
-            # Update tracking with all current errors
-            _notified_hms_errors[printer_id] = current_error_codes
     else:
     else:
         # No HMS errors - clear tracking so future errors get notified
         # No HMS errors - clear tracking so future errors get notified
         if printer_id in _notified_hms_errors:
         if printer_id in _notified_hms_errors: